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
0 Response to Confusion with looping
Post a Comment