Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: creating fixed variables from time-varying variables


From   "Buszin, Justin" <[email protected]>
To   <[email protected]>
Subject   st: creating fixed variables from time-varying variables
Date   Sat, 5 Apr 2008 16:37:35 -0400

I have person-year data that looks like this:
 
id     age     cedu
1        1         0
1        2         0
1        3         0
1        4         0
1        5         1
1        6         1
1        7         1
1        8         1
1        9         1
1       10        1
1       11        2
1       12        2
1       13        2
1       14        3
1       15        3
1       16        3
1       17        3
1       18        0
1       19        0
1       20        0
 
This is someone who is 20 years old and has a high school education ( for cedu, 0=no education that year, 1=elementary school, 2=middle school, 3=high school). I want to create a new variable called educattain, which is a fixed variable that represents the highest level of education a person obtained in their life. So imagine creating a fourth column where "3" fits into every cell for the above example, even past the age of 18 when the person's education is complete. I'm struggling to figure this out and think I need to use a series of "replace educattain=3 if id[_n]==[_n-1] & cedu==3 but this only fills the cells on the years the person was in high school. Can anyone please suggest a way around this? Thanks. 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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