Dear Stata 13 experts,
By using a panel dataset, I am working on a dynamic firms' total factor productivity (TFP) growth decomposition of Melitz and Polanec (2012) (Dynamic Olley- Pakes Productivity Decomposition with Entry and Exit) which is the second row of equation 6 in the paper attached. This decomposes TFP growth into 4 components:
- Change in unweighted mean TFP across continuing firms between year 2 and year 1;
- Change in the covariance between market shares and TFP for continuing firms;
- The difference between TFP of entering firms and the average TFP of continuing firms in the year 2;
- The difference between TFP of exiting firms and the average TFP of continuing firms in the year 1.
While I have been successful in building up the last three components, I am struggling in building up the first, which is the change in unweighted mean TFP across continuing firms between year 2 and year 1. Do you have any suggestion?
I have copied below part of the code. Equation 3 is the aggregate productivity change, while equation 4 is the decomposition. I have also attached the do file. In the rows 235-248 I try to build up such TFP component. This is followed by the other three, which I seem to build up successfully.
In the do file, group 1 refers to surviving firms, group 2 to entering firms, and group 3 to exiting ones. year 1 refers to 1998 and year 2 to 2007. `v' refers to firms' TFP. firm_id refers to each firm id. r_sales refer to each firm sales.
What do you think?
Thank you.
* Equation (3)
* THETAit - Firm's Output Share
bysort year: egen abc=total(r_sales) if group~=0 & group!=.
generate THETAit=r_sales/abc if group~=0 & group!=.
drop abc
* LLPt=SIGMATHETAit*lnPit - Aggregate Productivity Index at Time t
generate abc=THETAit*`v' if group~=0 & group!=.
bysort year: egen LLPt=total(abc) if group~=0 & group!=.
drop abc
* DELTAlnPt - Average Change in Aggregate Productivity Between Years 2 and 1
sort firm_id year
generate DELTALLPt=LLPt-L1.LLPt if group~=0 & group!=.
egen abc=mean(DELTALLPt) if group~=0 & group!=.
replace DELTALLPt=abc if group~=0 & group!=.
replace DELTALLPt=. if year==1 & group==1
drop abc
* Equation (4)
* Continuers: MEANLLPt - average TFP at time t
sort firm_id year
generate abc=THETAit*`v' if group==1
bysort year: egen MEANLLPt=mean(abc) if group==1
drop abc
* Continuers: DELTAMEANLLPt - Change in average TFP between time t=2 and t=1
sort firm_id year
generate DELTAMEANLLPt=MEANLLPt-L1.MEANLLPt if group==1 & year==2
generate continuers_wp=DELTAMEANLLPt
* Continuers: cross-plant - DELTAlnPit
sort firm_id year
generate DELTALLPit=`v'-L1.`v' if group==1 & year==2
* Continuers: cross-plant - DELTATHETAit
sort firm_id year
generate DELTATHETAit=THETAit-L1.THETAit if group==1 & year==2
* Continuers: cross-plant - continuers_cp=DELTAlnPit*DELTATHETAit
sort firm_id year
generate continuers_cp=DELTALLPit*DELTATHETAit if group==1 & year==2
* Entering plants
sort firm_id year
generate LLPt2=LLPt if group==1 & year==2
egen abc=mean(LLPt2)
replace LLPt2=abc
drop abc
generate abc=`v'-LLPt2 if group==2 & year==2
generate enterers=THETAit*abc if group==2 & year==2
drop abc LLPt2
* Exiting plants
generate LLPt1=LLPt if group==1 & year==1
egen abc=mean(LLPt1)
replace LLPt1=abc
drop abc
generate abc=LLPt1-`v' if group==3 & year==1
generate exiters=THETAit*abc if group==3 & year==1
drop abc LLPt1
* Total
generate continuers_tot=continuers_wp+continuers_cp
generate contribution=continuers_tot if continuers_tot!=.
replace contribution=enterers if enterers!=.
replace contribution=exiters if exiters!=.
By using a panel dataset, I am working on a dynamic firms' total factor productivity (TFP) growth decomposition of Melitz and Polanec (2012) (Dynamic Olley- Pakes Productivity Decomposition with Entry and Exit) which is the second row of equation 6 in the paper attached. This decomposes TFP growth into 4 components:
- Change in unweighted mean TFP across continuing firms between year 2 and year 1;
- Change in the covariance between market shares and TFP for continuing firms;
- The difference between TFP of entering firms and the average TFP of continuing firms in the year 2;
- The difference between TFP of exiting firms and the average TFP of continuing firms in the year 1.
While I have been successful in building up the last three components, I am struggling in building up the first, which is the change in unweighted mean TFP across continuing firms between year 2 and year 1. Do you have any suggestion?
I have copied below part of the code. Equation 3 is the aggregate productivity change, while equation 4 is the decomposition. I have also attached the do file. In the rows 235-248 I try to build up such TFP component. This is followed by the other three, which I seem to build up successfully.
In the do file, group 1 refers to surviving firms, group 2 to entering firms, and group 3 to exiting ones. year 1 refers to 1998 and year 2 to 2007. `v' refers to firms' TFP. firm_id refers to each firm id. r_sales refer to each firm sales.
What do you think?
Thank you.
* Equation (3)
* THETAit - Firm's Output Share
bysort year: egen abc=total(r_sales) if group~=0 & group!=.
generate THETAit=r_sales/abc if group~=0 & group!=.
drop abc
* LLPt=SIGMATHETAit*lnPit - Aggregate Productivity Index at Time t
generate abc=THETAit*`v' if group~=0 & group!=.
bysort year: egen LLPt=total(abc) if group~=0 & group!=.
drop abc
* DELTAlnPt - Average Change in Aggregate Productivity Between Years 2 and 1
sort firm_id year
generate DELTALLPt=LLPt-L1.LLPt if group~=0 & group!=.
egen abc=mean(DELTALLPt) if group~=0 & group!=.
replace DELTALLPt=abc if group~=0 & group!=.
replace DELTALLPt=. if year==1 & group==1
drop abc
* Equation (4)
* Continuers: MEANLLPt - average TFP at time t
sort firm_id year
generate abc=THETAit*`v' if group==1
bysort year: egen MEANLLPt=mean(abc) if group==1
drop abc
* Continuers: DELTAMEANLLPt - Change in average TFP between time t=2 and t=1
sort firm_id year
generate DELTAMEANLLPt=MEANLLPt-L1.MEANLLPt if group==1 & year==2
generate continuers_wp=DELTAMEANLLPt
* Continuers: cross-plant - DELTAlnPit
sort firm_id year
generate DELTALLPit=`v'-L1.`v' if group==1 & year==2
* Continuers: cross-plant - DELTATHETAit
sort firm_id year
generate DELTATHETAit=THETAit-L1.THETAit if group==1 & year==2
* Continuers: cross-plant - continuers_cp=DELTAlnPit*DELTATHETAit
sort firm_id year
generate continuers_cp=DELTALLPit*DELTATHETAit if group==1 & year==2
* Entering plants
sort firm_id year
generate LLPt2=LLPt if group==1 & year==2
egen abc=mean(LLPt2)
replace LLPt2=abc
drop abc
generate abc=`v'-LLPt2 if group==2 & year==2
generate enterers=THETAit*abc if group==2 & year==2
drop abc LLPt2
* Exiting plants
generate LLPt1=LLPt if group==1 & year==1
egen abc=mean(LLPt1)
replace LLPt1=abc
drop abc
generate abc=LLPt1-`v' if group==3 & year==1
generate exiters=THETAit*abc if group==3 & year==1
drop abc LLPt1
* Total
generate continuers_tot=continuers_wp+continuers_cp
generate contribution=continuers_tot if continuers_tot!=.
replace contribution=enterers if enterers!=.
replace contribution=exiters if exiters!=.