I have a dataset that includes total income, variable age ranges from 25 to 54, year from 1982 to 2018 and immigrant dummy variable. I want to generate two dummy variables for those who are at the top 1% and top10% of income distribution based on the year and age and then plot the share of those immigrants who are at the top 1% and top10% over years. So, basically, I generated the percentiles for each age group and for each year as follow:
Code:
gen ptile_inc=. forvalues a = 25/54 { xtile p`a' = totinc if age==`a' & year==1982 [aw=weight], nq(100) replace ptile_inc=p`a' if age==`a' & year==1982 } gen ptile_inc1=. forvalues a = 25/54 { xtile p1_`a' = totinc if age==`a' & year==1983 [aw=weight], nq(100) replace ptile_inc1=p1_`a' if age==`a' & year==1983 } gen top1_1982=(ptile_inc==100 | gen top1_1983=ptile_inc1==100 gen top10_1982=ptile_inc>90 gen top10_1983=ptile_inc1>90
0 Response to Percentile based on age and year using loop
Post a Comment