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

st: RE: Expanding observations and duplicating some values

From   "Steichen, Thomas J." <>
To   "''" <>
Subject   st: RE: Expanding observations and duplicating some values
Date   Wed, 25 Mar 2009 09:37:14 -0400

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

-----Original Message-----
From: [] On Behalf Of Hannah Goble
Sent: Wednesday, March 25, 2009 9:17 AM
Subject: st: Expanding observations and duplicating some values


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 Goble
Ph.D. Candidate
Department of Political Science
University of Wisconsin - Madison
110 North Hall
1050 Bascom Mall
Madison, WI 53706

*   For searches and help try:

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:

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