/*THIS CODE FOLLOWS METHODOLOGY WRITE-UP EXACTLY IN PROCESS AND VARNAMES Remember: 1. Use unsmoothed input variables, adjusted to control totals. 2. Make sure each household has only one head. 3. Make sure all consumption variables are non-negative. Note that cce, cch and ccx are current consumption for eduction, health and other non-durable, respectively. Note that cdr and cdd are durable consumption for housing and other durables, respectively. The variable "hh" is an indicator variable for the household head. The variable "householdid" is an id variable for the household. ***************************** * Calculate disposable income less current consumption, surplus and deficit: *****************************/ gsort householdid -hh gen X=yl+tgcash-tgtax+tfb-(cce+cch+ccx) gen sur=X*(X>0) gen def=X*(X<=0)*(-1) /***************************** * Sum at the household level *****************************/ egen surhh=sum(sur),by(householdid) egen defhh=sum(def),by(householdid) /******************************* * Find household tax rate * and current consump outflows * (need to define a shortfall variable to do this) *******************************/ gen ttax=min(1,defhh/surhh) replace ttax=0 if surhh==0 gen shortfall=max(0,defhh-surhh) gen tfwoc=0 replace tfwoc=(-1)*sur*(ttax) if hh==0 replace tfwoc=min(0,-(sur*ttax + shortfall - def)) if hh==1 /***************************************** * Find current consump inflows by sector * 1. Education * 2. Health * 3. All other expenditure (ccx) *****************************************/ gen tfwei=(cce/(cce+cch+ccx))*def if hh==0 gen tfwhi=(cch/(cce+cch+ccx))*def if hh==0 gen tfwxi=(ccx/(cce+cch+ccx))*def if hh==0 replace tfwei=(cce/(cce+cch+ccx))*max(def-shortfall,0) if hh==1 replace tfwhi=(cch/(cce+cch+ccx))*max(def-shortfall,0) if hh==1 replace tfwxi=(ccx/(cce+cch+ccx))*max(def-shortfall,0) if hh==1 replace tfwei=0 if cce+cch+ccx==0 replace tfwhi=0 if cce+cch+ccx==0 replace tfwxi=0 if cce+cch+ccx==0 /******************************************* * Find total consump inflows by sector for * use in outflow by sector calculation *******************************************/ egen tfweihh=sum(tfwei),by(householdid) egen tfwhihh=sum(tfwhi),by(householdid) egen tfwxihh=sum(tfwxi),by(householdid) /****************************************** * Find current consump outflows by sector ******************************************/ gen tfweo=(tfweihh/(tfweihh+tfwhihh+tfwxihh))*tfwoc gen tfwho=(tfwhihh/(tfweihh+tfwhihh+tfwxihh))*tfwoc gen tfwxo=(tfwxihh/(tfweihh+tfwhihh+tfwxihh))*tfwoc replace tfweo=0 if tfweihh+tfwhihh+tfwxihh==0 replace tfwho=0 if tfweihh+tfwhihh+tfwxihh==0 replace tfwxo=0 if tfweihh+tfwhihh+tfwxihh==0 /***************************************** * Transfers to household head for saving *****************************************/ gen tfwso=-sur-tfwoc if hh==0 replace tfwso=0 if hh==1 egen tfwsi=sum(tfwso),by(householdid) replace tfwsi=(-1)*tfwsi if hh==1 replace tfwsi=0 if hh==0 /****************************************** * Asset Transfers for Durable Consumption ******************************************/ gen tfwid=cdr+cdd if hh==0 replace tfwid=0 if hh==1 /*********************************************************** * All Transfers for Durable Consumption come from the head ***********************************************************/ egen tfwod=sum(tfwid),by(householdid) replace tfwod=(-1)*tfwod if hh==1 replace tfwod=0 if hh==0 /****************************************** * Asset Transfers for CATEGORIES OF Durable Consumption ******************************************/ gen tfwri=cdr if hh==0 replace tfwri=0 if hh==1 gen tfwdi=cdd if hh==0 replace tfwdi=0 if hh==1 egen tfwro=sum(tfwri),by(householdid) replace tfwro=(-1)*tfwro if hh==1 replace tfwro=0 if hh==0 egen tfwdo=sum(tfwdi),by(householdid) replace tfwdo=(-1)*tfwdo if hh==1 replace tfwdo=0 if hh==0 /****************************************** * MAKE TOTAL TRANSFER VARIABLES ******************************************/ gen tfwi=tfwei+tfwhi+tfwxi+tfwri+tfwdi+tfwsi gen tfwo=tfweo+tfwho+tfwxo+tfwro+tfwdo+tfwso /****************************************** * VERIFY THAT INFLOWS AND OUTFLOWS NET TO ZERO * *BY SECTOR *BY HOUSEHOLD *BY AGGREGATE ******************************************/ sort householdid foreach vvv in tfwei tfweo tfwhi tfwho tfwxi tfwxo tfwri tfwro tfwdi tfwdo tfwsi tfwso tfwi tfwo { egen `vvv'hhtot=sum(`vvv'), by(householdid) } egen aggi=sum(tfwi) egen aggo=sum(tfwo) gen prob1=(abs(tfweihhtot+tfweohhtot)>1) gen prob2=(abs(tfwhihhtot+tfwhohhtot)>1) gen prob3=(abs(tfwxihhtot+tfwxohhtot)>1) gen prob4=(abs(tfwrihhtot+tfwrohhtot)>1) gen prob5=(abs(tfwdihhtot+tfwdohhtot)>1) gen prob6=(abs(tfwsihhtot+tfwsohhtot)>1) gen prob7=(abs(tfwihhtot+tfwohhtot)>1) gen prob8=(abs(aggi+aggo)>1) /*The following variable SHOULD have only zeros in it!!!*/ egen anyprob=rowtotal(prob*) tab anyprob /* Drop intermediate variables and check variables*/ drop prob1-prob8 anyprob X sur def surhh defhh ttax shortfall tfweihh tfwhihh tfwxihh tfweihhtot-tfwohhtot aggi aggo