Dear Statalist,
I’m having problems with looping through variables. I am using Stata 15.1 for Windows.
I have a large dataset (please, see below) containing multiple measurement points of each individual. I want to generate a variable indicating individual's age at the year she gave birth to her first child (age_at_birth). For the first individual, this age would be 16 since the birth_year is 1999 and she was 16 years at 1999, for the second individual this age would be 16 since the birth_year is 1998 and she was 16 years at 1998, and so on. I understood the Stata command -forvalues- should be used but I did not manage to write a working code.
Moreover, I have a variable measuring occupation (nominal variable, gets values between 1 and 4) and I would like to generate a variable measuring individual's occupation one year before she gave birth to her first child (variable occup_1yr~h) and three years after she gave birth to her first child (occup_3yr_~h). Again, I think -forvalues- should be used for this kind of modifications and I am grateful for any tips on how to get started.
Array
Thank you very much for your help,
Julie
Related Posts with Confusion with looping
difference between mixed and hybrid models in analyzing panel dataI have been confused between hybrid model(xthybrid) and mixed model(xtmixed) in analyzing panel data…
Specify Range in Propensity Score MatchingDear All, I am using propensity score matching to match observations in current year with observati…
Histogram - adjusting the start of the x axisHello everyone! I am creating an epidemic curve using the histogram function. I have successfully cr…
Problem with the output for the margins post commandHi Statalisters, For the below example code, I defined label values for the group variable. However,…
Help create a new variableHello Statalist Forum, The following extracted data indicates different focus area employees of a s…
Subscribe to:
Post Comments (Atom)
0 Response to Confusion with looping
Post a Comment