Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: creation of a new variable using a variable condition

From   Riccardo Valboni <>
To   "" <>
Subject   st: creation of a new variable using a variable condition
Date   Fri, 21 Feb 2014 15:04:54 +0000

Dear statalist,

I am trying to do something that it's probably basic but I cannot get to the bottom of it.
I have a typical unbalanced panel dataset. Some of my observations happen to have an event at a certain point in time (coded 1 in the 'event' column). For them I would like to generate a new variable (newvar) that takes value 1 from the year of the first event onwards. The year of the first event obviously changes from case to case. (see the example below)

id      year    event   newvar
a       2001    0       0
a       2002    0       0
a       2003    1       1
a       2004    1       1
b       2005    0       0
b       2006    1       1
b       2007    0       1
b       2008    0       1
b       2009    0       1

I imagine that the command to do this starts with: by id... but I wouldn't know how continue that. Any suggestions?

Thank you!

De informatie verzonden in dit e-mail bericht is vertrouwelijk en is uitsluitend bestemd voor de geadresseerde van dit bericht. Lees verder: <>
The information in this e-mail message is confidential and may be legally privileged. Read more:<>

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index