*
* This STATA code produces -- in rtf-format -- tables 2, 3, 4, and 6 of Spamann, "Legal Origins, Civil Procedure, and the Quality of Contract Enforcement." It also calculates the rank correlations shown in tables 1 and 7 of that same article, and performs a number of specification tests relating to table 2. *
*



set more off
capture: log close

log using Spamann_civpro.log, replace

*
*
* (Table 1 -- corresponding variables, Spearman's rho) *
*

spearman procnumber db04_procnumber dlls_procnumber_c dlls_procnumber_e if year==2003, stats(rho p obs) pw
spearman procdays db04_procdays dlls_dur_total_c dlls_dur_total_e if year==2003, stats(rho p obs) pw
spearman proccost db04_proccost if year==2003, stats(rho p obs) pw
spearman db04_formalismindex  dlls_formalism_c dlls_formalism_e if year==2003, stats(rho p obs) pw

*
*
* "Table 2 -- The effects of complexity", & robustness checks *
*

local spec1 "ln_procdays ln_procnumber year"
local spec2 "ln_procdays lngdp ln_procnumber year"
local spec3 "ln_proccost ln_procnumber year"
local spec4 "ln_proccost lngdp ln_procnumber year"
local spec5 "ln_proccost lngdp ln_procnumber year if countrycode~="BTN""
local spec6 "BERI_enforce lngdp ln_procnumber if year==2003"

local fdspec1 "D.ln_procdays D.ln_procnumber"
local fdspec2 "D.ln_procdays D.lngdp D.ln_procnumber"
local fdspec3 "D.ln_proccost D.ln_procnumber"
local fdspec4 "D.ln_proccost D.lngdp D.ln_procnumber"
local fdspec5 "D.ln_proccost D.lngdp D.ln_procnumber if countrycode~="BTN"" 

local levels1 "ln_procnumber"
local levels2 "lngdp ln_procnumber"
local levels3 "ln_procnumber"
local levels4 "lngdp ln_procnumber"

local differences1 "D.ln_procnumber"
local differences2 "D.ln_procnumber D.lngdp"
local differences3 "D.ln_procnumber"
local differences4 "D.ln_procnumber D.lngdp"
local differences5 "D.ln_procnumber D.lngdp if countrycode~="BTN""

local squares1 "dln_procnumber2"
local squares2 "dln_procnumber2 dlngdp2"
local squares3 "dln_procnumber2"
local squares4 "dln_procnumber2 dlngdp2"
local squares5 "dln_procnumber2 dlngdp2"

*** Basic regression output ***

forval c=1/6 {
reg `spec`c'', cluster(countrycode)
estimates store ols`c'
}

esttab ols* using Spamann_table2, rtf replace b(a2) t(a2) se star(* .1 ** .05 *** .01) scalar(N_clust r2)  order(ln_procnumber lngdp year _cons) title(The effects of complexity) nonotes

forval c=1/5 {
reg `fdspec`c'', cluster(countrycode)
estimates store fd`c'
}

esttab fd* using Spamann_table2, rtf append b(a2) t(a2) se star(* .1 ** .05 *** .01) scalar(N_clust r2)  order(D.ln_procnumber D.lngdp _cons) extracols(6)

estimates drop _all


*** OLS vs FD ***

file open output using Spamann_specificationtests_for_table2.txt, write replace
file write output "Wald tests (generalized Hausmann tests) of equality of coefficients in OLS and FD specification, using variance matrix robust to heteroskedasticity and serial correlation:" _n

forval c=1/5 {
quietly: reg `spec`c''
estimates store ols`c'
quietly: reg `fdspec`c''
estimates store fd`c'
quietly: suest fd`c' ols`c', cluster(countrycode)
if (`c'==1 | `c'==3) test ([fd`c'_mean]D1.ln_procnumber=[ols`c'_mean]ln_procnumber) ([fd`c'_mean]_cons=[ols`c'_mean]year)
else test ([fd`c'_mean]D1.lngdp=[ols`c'_mean]lngdp) ([fd`c'_mean]D1.ln_procnumber=[ols`c'_mean]ln_procnumber) ([fd`c'_mean]_cons=[ols`c'_mean]year)
file write output "(`c'): Chi2(" (r(df)) ")= " (r(chi2)) ", two-sided p-value= " (r(p)) _n
estimates drop _all
}


*** FD vs FE ***

file write output _n(3) "Wooldridge (2002, 282-283) test for serial correlation in the error term of the FD specification (FE HO: rho=-.5):" _n

forval c=1/5 {
xtserial `spec`c''
file write output "(`c'): rho=" (r(corr)) ", p=" (r(p)) _n
}


*** Strict exogeneity ***

file write output _n(3) "Regression-based test of strict exogeneity of u_it implemented as F-test on x_t added to FD specification y_t-y_t-1=beta*x_t-x_t-1:" _n

forval c=1/4 {
quietly reg `fdspec`c'' `levels`c'', cluster(countrycode)
test `levels`c''
file write output "(`c'): F(" (r(df)) "," (r(df_r)) ")=" (r(F)) ", two-sided p-value=" (r(p)) _n
}

quietly reg D.ln_proccost D.lngdp D.ln_procnumber lngdp ln_procnumber if countrycode~="BTN", cluster(countrycode)
test lngdp ln_procnumber
file write output "(5): F(" (r(df)) "," (r(df_r)) ")=" (r(F)) ", two-sided p-value=" (r(p)) _n


*** Heteroskedasticity of FD residuals ***

file write output _n(3) "Test for heteroskedasticity of FD residuals e_it implemented as regression of e_it on squared first-differences of independent variables:" _n

forval c=1/5 {
quietly reg `fdspec`c''
predict e, resid
quietly reg e `squares`c'' `differences`c''
test `squares`c''
file write output "(`c'): F(" (r(df)) "," (r(df_r)) ")=" (r(F)) ", two-sided p-value=" (r(p)) _n
drop e
}

file close output


*
*
* "Table 3: Legal Origin and Procedural complexity ..." *
*

local i=1

xtreg ln_procnumber legor_civEC, be
estimates store civ_vs_com_`i++'
xtreg ln_procnumber legor_civEC lngdp, be
estimates store civ_vs_com_`i++'
xtreg ln_procdays legor_civEC, be
estimates store civ_vs_com_`i++'
xtreg ln_procdays legor_civEC lngdp, be
estimates store civ_vs_com_`i++'
xtreg ln_proccost legor_civEC, be
estimates store civ_vs_com_`i++'
xtreg ln_proccost legor_civEC lngdp, be
estimates store civ_vs_com_`i++'

esttab civ_vs_com_* using Spamann_table3, rtf replace se(2) r2(2) b(2) star(* .1 ** .05 *** .01) noobs scalar(N_g) sfmt(a1) label title(Legal origin and complexity, duration, and cost) nonotes

estimates drop _all

local i=1

xtreg ln_procnumber legor_frEC legor_geEC legor_scEC, be
estimates store legor_`i++'
xtreg ln_procnumber legor_frEC legor_geEC legor_scEC lngdp, be
estimates store legor_`i++'
xtreg ln_procdays legor_frEC legor_geEC legor_scEC, be
estimates store legor_`i++'
xtreg ln_procdays legor_frEC legor_geEC legor_scEC lngdp, be
estimates store legor_`i++'
xtreg ln_proccost legor_frEC legor_geEC legor_scEC, be
estimates store legor_`i++'
xtreg ln_proccost legor_frEC legor_geEC legor_scEC lngdp, be
estimates store legor_`i++'

esttab legor_* using Spamann_table3, rtf append se(2) b(2) r2(2) star(* .1 ** .05 *** .01) noobs scalar(N_g) sfmt(a1) label addnotes("The data are country averages for the period 2003-2008 (models 2, 4, and 6: 2003-2007)" "The legal origin classification is from La Porta et al. (2008)" "GDP data are PPP-adjusted and come from World Development Indicators online" "All other data are from World Bank (2009)")

estimates drop _all


*
*
* "Table 4: Legal-origin specific time trends ..." *
*

local depvar1 "D.ln_procnumber"
local depvar2 "D.ln_procdays"
local depvar3 "D.ln_proccost"


local i=1

forval c=1/3 {
reg `depvar`c'' legor_civEC D.lngdp, cluster(countrycode)
estimates store dynamics_`i++'
reg `depvar`c'' legor_frEC legor_geEC legor_scEC D.lngdp, cluster(countrycode)
estimates store dynamics_`i++'
}

esttab dynamics_* using Spamann_table4, rtf replace b(4) se(4) star(* .1 ** .05 *** .01) order(legor_civEC legor_frEC legor_geEC legor_scEC D.lngdp _cons) scalar(N N_clust r2) label title(Legal-origin specific time trends) addnotes("The legal origin classification is from La Porta et al. (2008)" "GDP data are PPP-adjusted and come from World Development Indicators online" "All other data are from World Bank (2009)")

estimates drop _all


*
*
* "Table 6: Legal origins and the enforceability of contracts" *
*

local i=1

reg BERI_enforce legor_civEC if year==2003
estimates store conf`i++'
reg BERI_enforce legor_frEC legor_geEC legor_scEC  if year==2003
estimates store conf`i++'
reg BERI_enforce legor_civEC lngdp  if year==2003
estimates store conf`i++'
reg BERI_enforce legor_frEC legor_geEC legor_scEC  lngdp  if year==2003
estimates store conf`i++'
reg BERI_enforce legor_civEC lngdp legor_so if year==2003
estimates store conf`i++'
reg BERI_enforce legor_frEC legor_geEC legor_scEC  lngdp legor_so if year==2003
estimates store conf`i++'
reg BERI_enforce legor_civEC  lngdp legor_so cpi2003 if year==2003
estimates store conf`i++'
reg BERI_enforce legor_frEC legor_geEC legor_scEC  lngdp legor_so cpi2003 if year==2003
estimates store conf`i++'



esttab conf* using Spamann_table6, rtf replace se(2) star(* .1 ** .05 *** .01) r2(2) b(2) order(legor_civEC legor_frEC legor_geEC legor_scEC) nogaps title(Legal origin and contract enforceability) addnotes("The dependent variable is enforceability of contracts in 2003 from BERI" "The legal origin classification is from La Porta et al. (2008)" "GDP data are for 2003 and are PPP-adjusted (from World Development Indicators online)" "Socialist/Transition is socialist legal origin from La Porta et al. (1999)" "Corruption is 10 minus Transparency International's Corruption Perception Index 2003")

estimates drop _all


*
*
* (Table 7: WBES and objective measures) *
*

spearman q_crt procdays db04_procdays dlls_dur_total_c dlls_dur_total_e DHMS_atimesale if year==2003, stats(rho p obs) pw
spearman aff_crt proccost db04_proccost DHMS_acost if year==2003, stats(rho p obs) pw


log close

* the end *