local lisco "au at be ca de dk es fi il it lu nl no uk us " /* *** please code above the country iso code you like to consider ****these lines just once to build the large dataset ****these lines just once to build the large dataset lissyuse, pvars(dname hid ppopwgt age sex relation) hvars(hid year iso2 hpopwgt dhi hifactor nhhmem region_c ) lis iso2(`lisco') from(1984) to(1987) save "$mydata/prosoc/tmplis16a" , replace lissyuse, pvars(dname hid ppopwgt age sex relation) hvars(hid year iso2 hpopwgt dhi hifactor nhhmem region_c ) lis iso2(`lisco') from(2010) to(2020) save "$mydata/prosoc/tmplis16b" , replace ****these lines just once to build the large dataset ****these lines just once to build the large dataset */ use "$mydata/prosoc/tmplis16a" , replace append using "$mydata/prosoc/tmplis16b" * we keep only the very first and the latest year for each country ... bysort iso2: egen maxy=max(year) bysort iso2: egen miny=min(year) keep if year==maxy | year==miny drop maxy miny * we keep only countries with 2 different years ... bysort iso2: egen maxy=max(year) bysort iso2: egen miny=min(year) keep if maxy!=miny drop maxy miny *useful variables such as country-year code, equivalised pre and post distribution household HH income... gen ccyyyy=iso2+string(year) gen gdhi=. gen ghif=. gen edhi=dhi/sqrt(nhhmem) gen ehif=hif/sqrt(nhhmem) *tricks: here is a series of standard treatment for LIS key figures compatibility... *drop "bad" disposable incomes drop if dhi==. | dhi==0 * select only if there is a weight gen hwgt=hpopwgt drop if hwgt==. | hwgt==0 * trick: create person weight as hwgt times number of household member * trick: this weight is non-zero and works "almost all the time" as frequency weight * BE CAREFUL = ONLY DESCRIPTIVE WEIGHT, NOT TO BE USED FOR REGRESSIONS, MODELS, etc.. generate wt=int(hwgt*nhhmem *100) *keep head of household HH, in "non elderly HH" keep if relation==1000 keep if age<65 *drop east germany, drop overseas france ... gen select =1 replace select =0 if iso2=="de" & region_c==4 replace select =0 if iso2=="de" & region_c==8 replace select =0 if iso2=="de" & region_c==13 replace select =0 if iso2=="de" & region_c==14 replace select =0 if iso2=="de" & region_c==16 replace select =0 if dname=="fr10" & region_c>=9 keep if select ==1 *trick: recode ccyyyy from 1 to max, max= total nb of countries-years... encode ccyyyy, gen(nname) su nname local max=r(max) *and then the loop for each country-year ... forvalues i=1/`max' { quietly { *trick: we make use of the lis-key-figures top and bottom codings... *gini is evaluated through the SJ+PVK ineqdec0 command ... *edhi income gini is then saved in a variable= sum edhi [w=wt] if nname==`i' generate botlin=0.01*_result(3) if nname==`i' replace edhi=botlin if edhitoplin & nname==`i' drop botlin toplin *we suppressed the gini calculations: this earns time... } } *we create 3 dummies = income class groups for poor, middle class and affluent household ... gen ppoor=. gen paff=. gen pmid=. *this loop to compute income class groups... qui { forvalues i=1/`max' { su edhi [w=wt] if nname==`i' , d replace ppoor= (edhi<=(r(p50)/2)) if nname==`i' replace paff= (edhi>=(r(p50)*1.5)) if nname==`i' replace pmid= ((paff+ppoor)==0) if nname==`i' } } * we create a cla variable 1/2/3 to obtain a table ... gen cla = ppoor+ 2*pmid+3*paff ta ccyyyy cla [w=wt] , row nofr * we create a time 1/2 variable based on maxy (see above) ... bysort iso2: egen maxy=max(year) gen time=(year==maxy)+1 *now the graphs: hbars of income class groups, for time 1 and 2 graph hbar ppoor pmid paff [w=wt] if time==1, over(ccyyyy, sort(2) ) /// stack percent blabel(bar, position(center) format(%5.1f) color(white)) legend(off) scale(.9) graphexportpdf $mypdf/graphteststata1.pdf, replace graph hbar ppoor pmid paff [w=wt] if time==2, over(ccyyyy, sort(2) ) /// stack percent blabel(bar, position(center) format(%5.1f) color(white)) legend(off) scale(.9) graphexportpdf $mypdf/graphteststata2.pdf, replace