local lisco "au ca de dk fi il 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 ineqdec0 edhi [w=hpop] if nname==`i' replace gdhi= r(gini) if nname==`i' ineqdec0 ehif [w=hpop] if nname==`i' replace ghif= r(gini) if nname==`i' } } *we then create a table by country/year... collapse gdhi ghif, by(ccyy iso2 year) * variable time (1 or 2) index of first and last year of a country gen n=1 sort iso2 year bysort iso2: gen time=sum(n) *gini of factor and disposable incomes as text 3 digits (truncated) gen gdhit=substr(string(gdhi),1,4) gen ghift=substr(string(ghif),1,4) *Trick: reshape wide encode iso2, gen(niso) reshape wide gdhi ghif gdhit ghift year ccyyyy , i(niso) j(time) *we sort by disposable income last year and prepare graph positions for labels sort gdhi2 gen gi=_n-.1 gen gi2=_n+.1 gen col=.15 gen pos=1 gen posb=3 *label by country with years... gen ccyyyyt=ccyyyy1 +"/"+ccyyyy2 *pcarrow graph with some tricks ... twoway (pcarrow gi gdhi1 gi gdhi2 ) (pcarrow gi2 ghif1 gi2 ghif2 ) /// (sca gi gdhi1 , ml(gdhit1 ) mlabposition(pos)) (sca gi gdhi2 , ml(gdhit2 ) mlabposition(pos)) /// (sca gi2 ghif1 , ml(ghift1 ) mlabposition(pos)) (sca gi2 ghif2 , ml(ghift2 ) mlabposition(pos)) /// (sca gi col , ml(ccyyyyt) mlabposition(posb) msymbol(none) mlabcolor(gs0) ) /// , scale(.7) xscale(range(.1 .55)) legend(off) yscale(off) *final magic wand to have the graph image exported visible on lissy... graphexportpdf $mypdf/graphteststata.pdf, replace