Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: RE: Expanding observations and duplicating some values


From   Howard Lempel <HLempel@brookings.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Expanding observations and duplicating some values
Date   Wed, 25 Mar 2009 09:46:45 -0400

Does -tsfill- take care of this problem?

xtset unit day
tsfill, full
replace numberofevents=0 if numberofevents==.
bysort unit (day): gen cum = sum(numberofevents)

You'll need to make a slight adjustment if Number of events is actually missing anywhere in the data and you don't want to turn that missing into zero.

Hope this helps.
Howie

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Steichen, Thomas J.
Sent: Wednesday, March 25, 2009 9:37 AM
To: 'statalist@hsphsun2.harvard.edu'
Subject: st: RE: Expanding observations and duplicating some values


fillin unit day
replace numberofevents=0 if numberofevents==.
bysort unit (day): gen cum = sum(numberofevents)

Please note that fillin will not anticipate the need for combinations of unit and day not in the dataset. For example, in your data below, there is no day value of 2; therefore combinations of unit = x and day = 2 will not be formed. If you want them, you will need to add a dummy record where day = 2.

-----------------------------------
Thomas J. Steichen
steicht@rjrt.com
-----------------------------------

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Hannah Goble
Sent: Wednesday, March 25, 2009 9:17 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: Expanding observations and duplicating some values

Everyone,

I have a relatively large data set of multiple units observed over a
length of days.  On each day, an event may occur or not; an event may
occur more than once per day.  Currently, on days in which no events
occur in a unit, there is no observation for that unit on that day,
but I'd like to have an observation for each unit on each day of the
observation period.  In other words, the data currently look something
like this,


Unit            Day             Number of Events        Cumulative Events
1               3                       4                                       4
1               5                       1                                       5
2               1                       1                                       1
3               3                       2                                       2
3               4                       1                                       3


and I'd like them to look like this,


Unit    Day             Number of Events        Cumulative Events
1               1                       0                                       0
1               2                       0                                       0
1               3                       4                                       4
1               4                       0                                       4
1               5                       1                                       5
2               1                       1                                       1


Each unit is missing a different number of observations, and, although
some of variables for the observations to be added will be zero, the
cumulative count variables need to take their values from the most
recent day on which an event occurred.  Does anyone have advice on
expanding these observations and getting Stata to pull some values
from existing observations?

Thank you for your time,
Hannah


Hannah Goble
Ph.D. Candidate
Department of Political Science
University of Wisconsin - Madison
110 North Hall
1050 Bascom Mall
Madison, WI 53706
hbgoble@wisc.edu



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

CONFIDENTIALITY  NOTE:  This e-mail message, including any attachment(s), contains information that may be confidential, protected by the attorney-client or other legal privileges, and/or proprietary non-public information. If you are not an intended recipient of this message or an authorized assistant to an intended recipient, please notify the sender by replying to this message and then delete it from your system. Use, dissemination, distribution, or reproduction of this message and/or any of its attachments (if any) by unintended recipients is not authorized and may be unlawful.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index