I have a dataset that contains a series of variables for each respondent, tracked over a certain range of their age (0 to the highest age they were tracked for). Currently, each respondent has a number of rows corresponding to the range of ages they were tracked for. For example, if a respondent was tracked up to the age of 30, then they have rows from age 0 to 30 in the dataset.
I want to standardize this so that each respondent has data rows from age 0 up to 60, regardless of their actual tracking period. If a respondent was not tracked for a certain age (for instance, any age above their last tracked age), I want these rows to still exist in the dataset, but with missing values in all the variable fields, except the ID and age. For example, if an individual was tracked until age 30, I would like to create additional rows for ages 31 to 60 for this individual, with all variables (emp, mar, ed) marked as missing for these additional years. Please is there a way to do this?
Data example with the persons Id, age, and three variables.
I want to standardize this so that each respondent has data rows from age 0 up to 60, regardless of their actual tracking period. If a respondent was not tracked for a certain age (for instance, any age above their last tracked age), I want these rows to still exist in the dataset, but with missing values in all the variable fields, except the ID and age. For example, if an individual was tracked until age 30, I would like to create additional rows for ages 31 to 60 for this individual, with all variables (emp, mar, ed) marked as missing for these additional years. Please is there a way to do this?
Data example with the persons Id, age, and three variables.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str10 ID long(Age emp ed mar) "0601004004" 0 6 4 20 "0601004004" 1 6 4 20 "0601004004" 2 6 4 20 "0601004004" 3 6 4 20 "0601004004" 4 6 3 20 "0601004004" 5 6 3 20 "0601004004" 6 6 6 20 "0601004004" 7 6 6 20 "0601004004" 8 6 6 20 "0601004004" 9 6 6 20 "0601004004" 10 6 6 20 "0601004004" 11 6 5 20 "0601004004" 12 6 5 20 "0601004004" 13 6 5 20 "0601004004" 14 6 1 20 "0601004004" 15 6 1 20 "0601004004" 16 6 1 20 "0601004004" 17 6 7 20 "0601004004" 18 6 7 9 "0601004004" 19 6 7 10 "0601004004" 20 6 7 10 "0601004004" 21 6 7 10 "0601004004" 22 6 7 10 "0601004004" 23 6 7 12 "0601004004" 24 6 7 12 "0601004004" 25 6 7 12 "0601004004" 26 6 7 12 "0601004004" 27 6 7 12 "0601004004" 28 6 7 12 "0601004004" 29 6 7 12 "0601004004" 30 6 7 12 "0601004004" 31 6 7 12 "0601004004" 32 6 7 12 "0601004004" 33 6 7 12 "0601004004" 34 6 7 12 "0601004004" 35 6 7 13 "0601004004" 36 6 7 13 "0601004004" 37 6 7 13 "0601004603" 0 6 4 20 "0601004603" 1 6 4 20 "0601004603" 2 6 4 20 "0601004603" 3 6 4 20 "0601004603" 4 6 4 20 "0601004603" 5 6 4 20 "0601004603" 6 6 4 20 "0601004603" 7 6 6 20 "0601004603" 8 6 6 20 "0601004603" 9 6 6 20 "0601004603" 10 6 6 20 "0601004603" 11 6 6 20 "0601004603" 12 6 6 20 "0601004603" 13 6 4 20 "0601004603" 14 6 4 20 "0601004603" 15 6 4 20 "0601004603" 16 6 4 20 "0601004603" 17 6 4 20 "0601004603" 18 6 4 20 "0601004603" 19 6 4 20 "0601004603" 20 6 4 20 "0601004603" 21 6 4 20 "0601004603" 22 6 4 20 "0601004603" 23 6 4 9 "0601004603" 24 6 4 10 "0601004603" 25 6 4 10 "0601004603" 26 6 4 12 "0601004603" 27 6 4 12 "0601004603" 28 6 4 12 "0601004603" 29 6 4 12 "0601004603" 30 6 4 12 "0601004603" 31 6 4 13 "0601004603" 32 6 4 13 "0601004603" 33 6 4 13 "0601004603" 34 6 4 13 "0601004603" 35 6 4 13 "0601004603" 36 6 4 13 "0601004603" 37 6 4 13 "0601004603" 38 6 4 13 "0601004603" 39 6 4 13 "0601005902" 0 6 4 20 "0601005902" 1 6 4 20 "0601005902" 2 6 4 20 "0601005902" 3 6 4 20 "0601005902" 4 6 4 20 "0601005902" 5 6 4 20 "0601005902" 6 6 6 20 "0601005902" 7 6 6 20 "0601005902" 8 6 6 20 "0601005902" 9 6 6 20 "0601005902" 10 6 6 20 "0601005902" 11 6 6 20 "0601005902" 12 6 5 20 "0601005902" 13 6 5 20 "0601005902" 14 6 5 20 "0601005902" 15 6 1 20 "0601005902" 16 6 1 20 "0601005902" 17 6 1 20 "0601005902" 18 6 7 20 "0601005902" 19 6 7 20 "0601005902" 20 6 7 20 "0601005902" 21 6 7 20 end label values emp emstate label def emstate 6 "Unemployed", modify label values ed ed_state label def ed_state 1 " general secondary", modify label def ed_state 3 "nursery", modify label def ed_state 4 "out of school", modify label def ed_state 5 "prep", modify label def ed_state 6 "primary", modify label def ed_state 7 "uni", modify label values mar markid_state label def markid_state 9 "married-0 child", modify label def markid_state 10 "married-1 child", modify label def markid_state 12 "married-2 child", modify label def markid_state 13 "married-3 child", modify label def markid_state 20 "single-0 child", modify
Comment