Hello,
I have data that is split by wave (4 years available), age group, sex and Life satisfaction. I would like to calculate the % of females within each age group for each year so that I can use this as a variable for regression.
I have so far written code which calculates % for one particular age group and year (code below). I am struggling to apply this to all age groups and waves so that I have a single variable that calculates separate % for each age group and wave.
Are there any pointers on the next steps I could take?
count if (Sex==1)&(Agegroup==1)&(Wave==1) ** counts number of females for first age group and wave
local numerator = r(N)
count if (Sex>=0)&(Agegroup==1)&(Wave==1) ** counts number of respondents for first age group and wave
local denominator = r(N)
gen percent =100*`numerator'/`denominator' ** generates a variable which is applied to ALL observations including the ones that should have a different %
Thanks
I have data that is split by wave (4 years available), age group, sex and Life satisfaction. I would like to calculate the % of females within each age group for each year so that I can use this as a variable for regression.
I have so far written code which calculates % for one particular age group and year (code below). I am struggling to apply this to all age groups and waves so that I have a single variable that calculates separate % for each age group and wave.
Are there any pointers on the next steps I could take?
count if (Sex==1)&(Agegroup==1)&(Wave==1) ** counts number of females for first age group and wave
local numerator = r(N)
count if (Sex>=0)&(Agegroup==1)&(Wave==1) ** counts number of respondents for first age group and wave
local denominator = r(N)
gen percent =100*`numerator'/`denominator' ** generates a variable which is applied to ALL observations including the ones that should have a different %
Thanks
Comment