I am using data from the National Longitudinal Survey of Youth 1997 set in wide format. My question is specific to the employment variables which capture whether a respondent is employed in a particular week of a particular year. In the example below, I have responses for employment in year 1998 weeks 49 to 52 and year 1999 weeks 1 to 3. This is just a snippet of the data which I have from 1994 to 2018.
I would like to create a continuous variable that captures the number of times a respondent records a '7' (employed) for a particular year so that I will know how many weeks a respondent has been employed in that year.
I am using wide format as my outcome variable and explanatory variable of interest are collected at two points in time.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(newE0011849 newE0011850 newE0011851 newE0011852 newE0011901 newE0011902 newE0011903) 7 7 7 7 7 7 7 5 5 5 5 5 5 5 5 5 5 5 5 5 5 1 1 5 5 5 5 5 1 1 1 1 1 1 1 5 5 5 5 5 5 5 1 1 1 1 1 1 1 5 5 5 5 5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 end
foreach x of local newempweeks1998 {
egen tot`x' = rsum(`x') if `x' == 7
}
Thanks in advance for your help on this.
0 Response to cumulative count of a specific value of a categorical variable across columns
Post a Comment