********************************************************************* **This programme is applying the tetrad method of Head et al. 2008.** **to run gravity regressions on large panels of trade flows, when ** **simple methods as LSDV are not practically doable ** **It does not make use of Cameron et al. (2006) multiway clustering,* **because this is intended to capture coefficients only. ** ********************************************************************* * *Please cite: *Head, K. Ries, J. and T. Mayer, 2008, "The erosion of colonial trade linkages after independence", CEPR DP 6951 *when using this code. * *First version: August 2008 *This version: Aug 2009 *contact: tmayer@univ-paris1.fr * *Requirements: * *1) The programme requires a list of variables where the first is the log of flows *and then the list of RHS variables. Those should vary by dyad and time, although *including variables like distance won't make the programme crash. * *2) The programme looks for three variables iso_o iso_d and year, that must be there. *iso_o designates the exporting country, iso_d the importer, and both variables should *be string. * *3) The programme needs a reference importer and a reference exporter to be specified *as k and ell options respectively. For instance, when taking USA as a reference importer *and Germany as a reference exporter, syntax looks like: *tetrad lx rta gatt cu, k(USA) ell(DEU) * *4) The programme transforms your original data, so one needs to do a "save temp,replace ... use temp,clear" *before and after running it. * *Start of programme: program define tetrad_areg, eclass byable(onecall) sortpreserve syntax varlist [if] [in], K(string) ELL(string) ******************************************* *0) Saving original dataset to be restored* ******************************************* qui save tetradtemp, replace * *************** *1) Tetrading * *************** *variables to be tetraded global vars "`varlist'" local numvars : word count `varlist' * foreach x of varlist $vars{ qui drop if `x'==. } *set reference countries global k = "`k'" global ell = "`ell'" qui gen byte k = iso_d == "$k" di in white "***********************" di in green "Reference importer: " "`k'" di in green "Reference exporter: " "`ell'" sort year iso_o k foreach x of varlist $vars { qui by year iso_o : gen `x'r=`x'-`x'[_N] if iso_d[_N]=="$k" } qui save ttemp,replace * use ttemp, clear qui keep if iso_o=="$ell" foreach x in $vars { rename `x'r `x'r_rec } qui keep iso_d year *_rec sort year iso_d qui save ttemp1,replace * use ttemp,clear sort year iso_d qui merge year iso_d using ttemp1 * foreach x in $vars { qui replace `x'r = `x'r - `x'r_rec qui replace `x' = `x'r label var `x' " `x' tetraded" qui drop `x'r } *each variable is now tetraded, but keeps same name drop *r_rec _merge k * qui drop if iso_d=="`k'"|iso_o=="`k'"|iso_d=="`ell'"|iso_o=="`ell'" * cap drop yr* qui tab year, gen(yr) qui sum year local numyr = r(max) - r(min) +1 * di in green "First year: " r(min) di in green "Last year: " r(max) * foreach x of varlist $vars{ qui drop if `x'==. } * *qui save ttest, replace erase ttemp.dta erase ttemp1.dta di in white "***********************" di in ye "End of tetrading" * **************** *2) Regression * **************** * di in green "Number of variables: `numvars' " di in green "List of variables: `varlist' " *defining variables global tvar = "`varlist'" global RHS = "$tvar" * cap drop dyad egen dyad=group(iso_o iso_d) * di in yellow "Start of regression:" di in white "********************" areg `varlist' yr2-yr`numyr', absorb(dyad) * ****************************** *3)Restoring original dataset* ****************************** qui use tetradtemp, clear qui erase tetradtemp.dta end