I am trying to calculate trade costs following the methodology outlined by Novy (2012). The code and example data used are provided below. While the results are fine, the structure of the code seems rather rudimentary. suggestions to enhance the sophistication of the do-file would be greatly appreciated.
Code:
clear all input str3 exporter str3 importer year trade "IND" "UAE" 1990 500 "UAE" "IND" 1990 600 "IND" "IND" 1990 1000 "UAE" "UAE" 1990 1200 "IND" "UAE" 1991 550 "UAE" "IND" 1991 650 "IND" "IND" 1991 1100 "UAE" "UAE" 1991 1250 end save trade_cost.dta, replace preserve gen intratrade= trade if exporter==importer keep exporter year intratrade drop if intratrade==. save intratrade1.dta, replace restore merge m:1 exporter year using intratrade1 drop _merge rename intratrade intratrade_exp save trade_cost.dta, replace preserve use intratrade1.dta rename exporter importer save intratrade1.dta, replace restore merge m:1 importer year using intratrade1 rename intratrade intratrade_imp drop _merge drop if exporter==importer save trade_cost.dta, replace preserve rename importer importer1 rename exporter importer rename importer1 exporter rename trade trade_imp keep importer exporter year trade save Inter_trade.dta, replace restore merge 1:1 exporter importer year using Inter_trade.dta drop _merge rename trade trade_exp * Set theta parameter scalar theta = 8 * Compute trade costs with robust error handling gen tau = . replace tau = ((intratrade_exp*intratrade_imp)/(trade_exp*trade_imp))^(1/(2*(theta-1))) - 1
Comment