/*This program calculates mobility measure of Table 1 in "On the Evaluation of Economic Mobility" by Gottschalk and Spolaore in May 2001 Set parameters for gamma, epsilon and rho at the beginning of the program the sample data comes from PSID 1984-1993*/ clear set mem 100m set more off program drop _all use mobility.dta, clear //set parameters here for gamma, epsilon, rho global gamma=0 global epsilon=2 global rho=0 program define mobility global scale=-3 quietly generate alpha=.5 quietly generate double u2=. quietly generate double ksmu2=. quietly generate double xxx=. quietly generate double yyy=. //Rescale to avoid underflows when take xxx^-10 etc quietly replace c1=c1*10^$scale quietly replace c2=c2*10^$scale //Generate hypothetical income (c12) //STEP #1--Create multiple cases. /* If don't do this then will match with persons with different weights and as result mean c12~= mean c2 (alerted to this problem because reverse was not one even when rho and gamma were equal) */ sum wt // Need integer weights to expand data set quietly gen wt2=wt replace wt2=1 if wt2<1 sum wt2 quietly replace wt2=round(wt2,1) sort c1 quietly generate original=_N expand wt2 quietly generate new=. quietly replace new=1 if _n>original quietly replace new=0 if _n<=original //STEP #2---Generate hypothetical earnings (c12) tempfile temp1 temp2 sort c1 quietly generate id=_n save `temp1',replace quietly rename c2 c12 keep c12 sort c12 quietly generate id=_n sort id save `temp2',replace use `temp1' sort id merge id using `temp2' drop _merge id original /*Step #3 Collapse the data set back down to observations with unique matches and reweight appropriately. NOTE There will be more observations than originally since some y1's will be matched with more than one c3, leading to more than one unique match with the c1.*/ sort ppid c12 quietly by ppid c12: replace wt=_N quietly by ppid c12: gen obs=_n sum [weight=wt] if obs==1 keep if obs==1 //Calc values that don't depend on parameters //Equal is utility if there were total equality quietly generate cbar1=(1-alpha)*c1+alpha*c2 quietly sum cbar1 [weight=wt] global cbar=_result(3) set rmsg on outer end program define getratio //Utility Calulations //Utility knowing c2 --Ar /*Ar measures the fraction of consumption cbar that individuals in a society with reversal (but complete knowledge about c2)would be willing to sacrifice in order to achieve equality of consumption*/ //1-alpha is alpha1 in paper, alpha is alpha2 in paper //Wr is given in equation (3.5) with c2 given in equation (2.9) quietly replace xxx=(1-alpha)*c1^(1-$rho) quietly replace xxx=xxx+alpha*[c2^(1-$gamma)]^[(1-$rho)/(1-$gamma)] quietly replace xxx=xxx^[(1-$epsilon)/(1-$rho)] quietly summarize xxx [weight=wt] global Wr=(_result(3)^[1/(1-$epsilon)]) //Utility in static society--As /*As is a measure of relative welfare loss from inequality*/ //Ws is given in equation (3.1), c12 has the form of equation (2.9) quietly replace xxx=(1-alpha)*c1^(1-$rho) quietly replace xxx=xxx+alpha*[c12^(1-$gamma)]^[(1-$rho)/(1-$gamma)] quietly replace xxx=xxx^[(1-$epsilon)/(1-$rho)] quietly summarize xxx [weight=wt] global Ws=(_result(3)^[1/(1-$epsilon)]) //Utility based on ksm expectation--late resolution--Ao /*Ao measures the fraction of consumption cbar that individuals are willing to sacrifice in order to achieve equality of consumption across people and across periods*/ quietly replace u2=c2^(1-$gamma) drop ksmu2 ksm u2 c1 ,nograph weight bwidth(.2) gen(ksmu2) /* Mean of Kernel smoothed means is not in general equal to the weighted mean leading Wu to be slightly different from 1 even when rho=gamma=epsilon Adjustment to impose this constraint. Note the adjust option in ksm equates the unweighted means so can't use it */ quietly sum u2 [weight=wt] quietly replace xxx=_result(3) quietly sum ksmu2 [weight=wt] quietly replace yyy=_result(3) quietly replace ksmu2=ksmu2*(xxx/yyy) quietly replace xxx=(1-alpha)*c1^(1-$rho) quietly replace xxx=xxx+alpha*ksmu2^[(1-$rho)/(1-$gamma)] quietly replace xxx=xxx^[(1-$epsilon)/(1-$rho)] quietly summarize xxx [weight=wt] global Wo=(_result(3)^[1/(1-$epsilon)]) end program define outer display $gamma $epsilon $rho getratio quietly generate As=1-$Ws/$cbar quietly generate Ar=1-$Wr/$cbar quietly generate Ao=1-$Wo/$cbar //"reverse" is welfare gains from reversal quietly generate reverse=Ar-As //"later" is welfare impact of time independence quietly generate later=Ao-Ar list As Ar Ao reverse later in 1/1 end mobility