Dear all,
I would like to create a single variable from two already existing ones in my dataset, taking into account (of course) the missing variables in the two existing ones.
How could I do this in the cleanest and most programming-correct way in Stata?
The two variables I am interested in are coded from 1 to 5 and from 1 to 5, respectively. However, these variables evaluate different parameters. Here is the code if it helps:
And also:
Thanks in advance for your help.
--
Michael
I would like to create a single variable from two already existing ones in my dataset, taking into account (of course) the missing variables in the two existing ones.
How could I do this in the cleanest and most programming-correct way in Stata?
The two variables I am interested in are coded from 1 to 5 and from 1 to 5, respectively. However, these variables evaluate different parameters. Here is the code if it helps:
Code:
gen ba_hes_heu = cond(inlist(1, bachelor_hes),1, /// cond(inlist(1, bachelor_heu),2, /// cond(inlist(2, bachelor_hes),3, /// cond(inlist(2, bachelor_heu),4, /// cond(inlist(3, bachelor_hes),5,.))))) * * * ba_hes_heu == 1 if HES-SO; == 2 if HEU without GE; ==3 if HESGE; * == 4 if UNIGE; == 5 if Others BA HES; "." otherwise * label define bache_hes_heu 1 "BA HES-SO hors GE" 2 "BA Autres HEU" /// 3 "BA HES-GE" 4 "BA HEU-GE" 5 "BA Autres HES" label value ba_hes_heu bache_hes_heu label var ba_hes_heu "Bachelor HES/HEU Confondus"
Code:
gen ma_hes_heu = cond(inlist(1, master_hes),1, /// cond(inlist(1, master_heu),2, /// cond(inlist(2, master_hes),3, /// cond(inlist(2, master_heu),4, /// cond(inlist(3, master_hes),5,.))))) * * label define master_hes_heu 1 "MA HES-SO hors GE" 2 "MA Autres HEU" /// 3 "MA HES-GE" 4 "MA HEU-GE" 5 "MA Autres HES" label value ma_hes_heu master_hes_heu label var ma_hes_heu "Master HES/HEU Confondus" * ma_hes_heu == 1 if HES-SO; == 2 if HEU without GE; ==3 if HESGE; * == 4 if UNIGE; == 5 if Others BA HES; "." otherwise
--
Michael
Comment