Hello,
This is my first time posting and I'm a stata novice so please bear with me.
I'm trying to construct a synthetic panel using the Survey of Consumer Finances from the Federal Reserve. They've put out a survey every three years since 1989 (so there are 8 surveys in all).
My goal is to create 15 cohorts of people based on their age, and group three ages together in each cohort. For example this is my original code for my first cohort in 1989.
gen cohort=age
replace cohort=1 if age==27 | age==28 | age==29
replace cohort=2 if age==30 | age==31 | age==32
replace cohort=3 if age==33 | age==34 | age==35
replace cohort=4 if age==36 | age==37 | age==38
replace cohort=5 if age==39 | age==40 | age==41
replace cohort=6 if age==42 | age==43 | age==44
replace cohort=7 if age==45 | age==46 | age==47
replace cohort=8 if age==48 | age==49 | age==50
replace cohort=9 if age==51 | age==52 | age==53
replace cohort=10 if age==54 | age==55 | age==56
replace cohort=11 if age==57 | age==58 | age==59
replace cohort=12 if age==60 | age==61 | age==62
replace cohort=13 if age==63 | age==64 | age==65
replace cohort=14 if age==66 | age==67 | age==68
replace cohort=15 if age==69 | age==70 |age==71
replace cohort=. if age>61 & if age<27
label define cohort 1 "27-29" 2 "30-32" 3 "33-35" 4 "36-38" 5 "39-41" 6 "42-44" 7 "45-47" 8 "48-50" 9 "51-53" 10 "54-56" 11 "57-59" 12 "60-62" 13 "63-65" 14 "66-68" 15 "69-71" 16 ">71"
In 1992, each age group in each cohort would be three years older, and so on.
I've managed to create a loop to do commands that are uniform for every version of the survey, but I can't figure out how to automate the creation of these cohorts (and any calculations I want to do on them).
Here is my code for the original loop:
local filelist: dir . files "H:\stata\scf`y'.dta",
foreach y in 1989 1992 2001 2004 2007 2010 2013 2016 {
display "`y'"
use "H:\stata\scf`y'.dta", clear
Is there a way to create these groups of ages in each survey, increasing by 3 years each time using a loop? It's a huge amount of data so I am trying to avoid merging all 8 datasets.
Thank you in advance for all of your help!
This is my first time posting and I'm a stata novice so please bear with me.
I'm trying to construct a synthetic panel using the Survey of Consumer Finances from the Federal Reserve. They've put out a survey every three years since 1989 (so there are 8 surveys in all).
My goal is to create 15 cohorts of people based on their age, and group three ages together in each cohort. For example this is my original code for my first cohort in 1989.
gen cohort=age
replace cohort=1 if age==27 | age==28 | age==29
replace cohort=2 if age==30 | age==31 | age==32
replace cohort=3 if age==33 | age==34 | age==35
replace cohort=4 if age==36 | age==37 | age==38
replace cohort=5 if age==39 | age==40 | age==41
replace cohort=6 if age==42 | age==43 | age==44
replace cohort=7 if age==45 | age==46 | age==47
replace cohort=8 if age==48 | age==49 | age==50
replace cohort=9 if age==51 | age==52 | age==53
replace cohort=10 if age==54 | age==55 | age==56
replace cohort=11 if age==57 | age==58 | age==59
replace cohort=12 if age==60 | age==61 | age==62
replace cohort=13 if age==63 | age==64 | age==65
replace cohort=14 if age==66 | age==67 | age==68
replace cohort=15 if age==69 | age==70 |age==71
replace cohort=. if age>61 & if age<27
label define cohort 1 "27-29" 2 "30-32" 3 "33-35" 4 "36-38" 5 "39-41" 6 "42-44" 7 "45-47" 8 "48-50" 9 "51-53" 10 "54-56" 11 "57-59" 12 "60-62" 13 "63-65" 14 "66-68" 15 "69-71" 16 ">71"
In 1992, each age group in each cohort would be three years older, and so on.
I've managed to create a loop to do commands that are uniform for every version of the survey, but I can't figure out how to automate the creation of these cohorts (and any calculations I want to do on them).
Here is my code for the original loop:
local filelist: dir . files "H:\stata\scf`y'.dta",
foreach y in 1989 1992 2001 2004 2007 2010 2013 2016 {
display "`y'"
use "H:\stata\scf`y'.dta", clear
Is there a way to create these groups of ages in each survey, increasing by 3 years each time using a loop? It's a huge amount of data so I am trying to avoid merging all 8 datasets.
Thank you in advance for all of your help!
Comment