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
How do I make a value repeat itself across observations per ID?I have variables ID, Name, Age and Income. Income is the income of the household head. I want the in…
Making long labels wrap into two lines using esttab on latexHi all, I am trying to tabulate some variables and export the data to latex using esttab (command f…
Using inverse probability weights to increase balance among covariatesHello. I'm running a difference-in-difference model, and so have two groups. I'm using inverse proba…
Between Group Baseline Difference in Randomized Control Trial?I know many of you are much smarter than I.. I'm analyzing data for an RCT with relatively small n (…
Customizing legend of twoway graph.Dear All, I am making a twoway graph as follows: Code: twoway (scatter daysMED week if dateWeek&…
Subscribe to:
Post Comments (Atom)
0 Response to Generate a new variable
Post a Comment