I am trying to generate a variable for the age of the oldest male in the household.
So, I am using the variables from the household roster in the NIDS dataset.
I have identified variables such as a household residence or living in the household, gender (male) and year of birth (age).
I want to generate or create a variable for the age oldest male in the household.
Then, I want to place him (male) side by side with the female that is receiving benefit within the same household.
Please see what I have done in my dofile;
******** generating age of the oldest male ********// generating male age
*1* living in the residence according to household roster
codebook r_pres
numlabel, add
tab r_pres
gen hhres=.
replace hhres=1 if r_pres==1
*replace hhres=0 if r_pres==2
*drop if r_pres==3
* // Just rename
*ren r_pres hhres
*2* year of birth to generate age in the household roster
codebook r_dob_y
tab r_dob_y
drop if r_dob_y==9999
ren r_dob_y ageh
gen yr=2017
gen agehh=yr-ageh
tab agehh
*3* gender / sex in the household roster
br r_gen
*ren r_gen // male = 1, female = 2 //
gen sexM=.
replace sexM=1 if r_gen==1
replace sexM=0 if r_gen==2
tab sexM
*4* females receiving the benefit
OAPr
*/ age of the oldest male living in the household (AOmhh) ********//
egen AOmhh= max(agehh) if sexM==1 & hhres==1, by (pid)
Please, how do I generate a variable age of the oldest male in the household?
Thanks in anticipation for your help.
Related Posts with Generate a new variable
Tabulation based on multiple categorical variablesI am using Stata 17 and I’d like to produce a frequency table (tabulate one way) based on multiple v…
grouping dimensions with bordersI want horizontal lines separating my the levels of my first dimension. I can almost obtain this usi…
Time series dummy variableHi all, I am trying to make a time-series line plot for employment as a dummy variable (called "lfs…
Quarter Averages to Yearly AveragesHello, Code: * Example generated by -dataex-. For more info, type help dataex clear input float(fu…
From monthly to yearly in %Hello! Code: * Example generated by -dataex-. For more info, type help dataex clear input float(fu…
Subscribe to:
Post Comments (Atom)
0 Response to Generate a new variable
Post a Comment