Statalist


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

Re: st: creating fixed variables from time-varying variables


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: creating fixed variables from time-varying variables
Date   Sat, 5 Apr 2008 20:55:29 +0000 (GMT)

You can do this in one command by combining the -bys- command with the -egen- command:

bys id: egen educattain = max(cedu)


see -help by- and -help egen- for more information.

Hope this helps,
Maarten
 -----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands


visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434


+31 20 5986715


http://home.fsw.vu.nl/m.buis/
-----------------------------------------


----- Original Message ----
From: "Buszin, Justin" <[email protected]>
To: [email protected]
Sent: Saturday, 5 April, 2008 10:37:35 PM
Subject: st: creating fixed variables from time-varying variables

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/



      ___________________________________________________________ 
Yahoo! For Good helps you make a difference  

http://uk.promotions.yahoo.com/forgood/

*
*   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