*Change Directory to the local version

global dir ""C:\Users\vanreene\Dropbox (WMS)\TITC_2019\_November2020\Replication\"


cd "$dir"

*Run pat_builder_Sept2020 to set up files

cap log c
log using CM_Response_Revised_v2,replace t 

clear all 
set more off
set matsize 2000
version 15.1

*Use the sample from the original Bloom, Draca and Van Reenen (2016) paper, Table 2. Sourced from https://academic.oup.com/restud/article/83/1/87/2461318 

/*********/
/*TABLE 1*/
/*********/

use "titc_bdvr_pat.dta", clear
*Use the sample used in BDVR Table 7
keep if (max_pp==1 | t_sample==1)
so bvd year
*Add in differences calculated using DHS and IHS
*merge bvd year using "dhsihs.dta"
merge bvd year using "extra_vars.dta"

cap estimates drop *
so num year
tsset num year


cap estimates drop *
keep if x_init_all!=.

*Column 1: PAT+1, BDVR version (replicates 7 column (3))
eststo:xi: nbreg   pat_count1 multi_chimp i.year i.cty i.max_sic4  init_lpstock0 init_patDum0 if max_pp==1, cluster(max_cult)
*Column 2: PAT, CM version  
eststo:xi: nbreg   pat_count multi_chimp i.max_sic4 i.cy init_lpstock0 init_patDum0                  if max_pp==1, cluster(max_cult)
*Column 3: PAT, CM version plus add initial imports
eststo:xi: nbreg   pat_count multi_chimp i.max_sic4 i.cy init_lpstock0 init_patDum0 init_multi_chimp if max_pp==1,cluster(max_cult)
*Column 4: PAT, Use only single industry and define initial conditions 1990-1996. Exactly what TC asks for
eststo:xi: nbreg     pat_count chimp_sing_new x_init_all init_lpstock0 init_patDum0  i.max_sic4 i.cy  ,cluster(max_cult)
*Column 5: PAT, Use only single industry and define initial conditions by cohort. 
eststo:xi: nbreg     pat_count chimp_sing_new init_sing init_lpstock0 init_patDum0  i.max_sic4 i.cy  ,cluster(max_cult)

esttab using Tab1.csv, replace stats(N, fmt(%9.0f %9.0g)) cells(b(star fmt(3)) se(par fmt(3))) starlevels( * 0.10 ** 0.05 *** 0.01) /// 
title("Count Data Models with controls for initial Chinese Imports") keep( multi_chimp init_multi_chimp chimp_sing_new  x_init_all init_sing )nogap 
 

/*********/
/*TABLE A1*/
/*********/
cap estimates drop *
*Column 1: PAT, CM version plus add initial imports
eststo:xi: poisson   pat_count multi_chimp i.max_sic4 i.cy init_lpstock0 init_patDum0 init_multi_chimp if max_pp==1,cluster(max_cult)
*Column 2: PAT, Use only single industry and define initial conditions 1990-1996. Exactly what TC asks for
eststo:xi: poisson     pat_count chimp_sing_new x_init_all init_lpstock0 init_patDum0  i.max_sic4 i.cy  ,cluster(max_cult)
*Column 3: PAT, Use only single industry and define initial conditions by cohort. 
eststo:xi: poisson     pat_count chimp_sing_new init_sing init_lpstock0 init_patDum0  i.max_sic4 i.cy  ,cluster(max_cult)

esttab using TabA1.csv, replace stats(N, fmt(%9.0f %9.0g)) cells(b(star fmt(3)) se(par fmt(3))) starlevels( * 0.10 ** 0.05 *** 0.01) /// 
title("Poisson Count Data Models with controls for initial Chinese Imports") keep(multi_chimp chimp_sing_new  x_init_all init_sing )nogap 
 
 
log c
stop
