*This dofile estimates AD Probits on 5-6 digit NAICS data for AER revision. #delimit ; clear matrix; clear; set mem 700m; set more off; * set path; * (this is the only time that the absolute path is set in this code); cd "C:\mypath" ; log using Estimation-Table-2-05-01-2012, replace; /* ***************************************************************************** */ /* ** TABLE 2: Specification (1): Baseline model ** */ /* ***************************************************************************** */ clear; use "SETA_estim_final_05-01-2012.dta"; /* RESCALE VARIABLES */ replace gr_imp_L1=gr_imp_L1/10000; replace sd_imp_gr= sd_imp_gr/100; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum/1000; replace chg_rxr_L1= chg_rxr_L1/1000; *Generate the interacted continuous variables; gen MDXS_imp= ln_inv_es_id_elast_sum*gr_imp_L1; *As a dprobit; dprobit AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1, robust; mfx compute; *As a probit, with interaction; probit AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1, robust; keep if e(sample)==1; sum AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1; *Calculate marginal effects; *To verify code, start by recreating dprobit coefficients; predict x_beta1, xb; egen av_xbeta1=mean(x_beta1); scalar phi1=normalden(av_xbeta1); scalar list phi1; matrix marg=phi1*e(b); matrix list marg; *Next, calculate the interaction terms we’re interested in; egen av_imp_gr=mean(gr_imp_L1); egen av_elast=mean(ln_inv_es_id_elast_sum); gen me_imports= (_b[gr_imp_L1]+_b[MDXS_imp]*av_elast)*phi1; gen me_elast= (_b[ln_inv_es_id_elast_sum]+_b[MDXS_imp]*av_imp_gr)*phi1; /* ***************************************************************************** */ /* THESE ARE THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum me_imports; sum me_elast; *Calculate std errors of marginal effects; *To verify code, start by recreating dprobit coefficients; *Note that when working with the probit command, “robust,” the vce matrix is robust and the associated std errors are the “robust” std errors from dprobit; *define the VCE matrix; matrix varcov=e(V); matrix list varcov; *extract the diagonal of the vce matrix; matrix vc_row=vecdiag(varcov); *construct a new matrix with zeros on the off-diagonal; matrix vc_diag=diag(vc_row); *take the square root of the diagonal elements; matrix std_err=cholesky(vc_diag); *scale up to marginal effects; matrix std_err_marg=phi1*std_err; matrix std_err_scaled=vecdiag(std_err_marg); matrix list std_err_scaled; matrix list varcov; gen var_me_imp =varcov[1,1]+(varcov[4,4]*(av_elast^2)) +2*av_elast*varcov[1,4]; gen sqrt_var_imp=var_me_imp^(.5); gen std_err_me_imp=sqrt_var_imp*phi1; gen var_me_elast=varcov[3,3] +(varcov[4,4]*(av_imp_gr^2))+2*av_imp_gr*varcov[3,4]; gen sqrt_var_elast=var_me_elast^(.5); gen std_err_me_elast=sqrt_var_elast*phi1; /* ***************************************************************************** */ /* THESE ARE THE STANDARD ERRORS OF THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum std_err_me_imp; sum std_err_me_elast; ************************************************************************************************; *PREDICTION: quantify the effect on the prob of a one std dev shock for interaction terms; ************************************************************************************************; *Calculate the predicted value at the mean of the dataset; predict x_beta_1; sum x_beta_1; *Generate local variables equal to the mean and std dev of gr_imp_L1; egen gr_imp_L1_mean= mean(gr_imp_L1); egen gr_imp_L1_sd=sd(gr_imp_L1); gen gr_imp_L1_saved=gr_imp_L1; replace gr_imp_L1= gr_imp_L1_mean + gr_imp_L1_sd; *Generate local variables equal to the mean and std dev of the elasticities; egen ln_inv_es_id_elast_sum_mean= mean(ln_inv_es_id_elast_sum); egen ln_inv_es_id_elast_sum_sd=sd(ln_inv_es_id_elast_sum); *Part 1: Consider the effect on the probability of a one std deviation shock to import growth; predict x_beta_2; sum x_beta_2; gen MDXS_imp_saved=MDXS_imp; replace MDXS_imp= ln_inv_es_id_elast_sum*(gr_imp_L1_mean+gr_imp_L1_sd); /* ***************************************************************************** */ /* THIS (x_beta_3) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO IMP GROWTH */ predict x_beta_3; sum x_beta_3; *Part 2: Consider the effect of a one standard deviation shock to the elasticity measure; *First, change those values back to the means; replace gr_imp_L1=gr_imp_L1_saved; replace MDXS_imp=MDXS_imp_saved; /* ***************************************************************************** */ *Check that this (x_beta_4) is the same as x_beta_1 so the original data is reloaded into memory; predict x_beta_4; sum x_beta_4; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum_mean + ln_inv_es_id_elast_sum_sd; predict x_beta_5; sum x_beta_5; replace MDXS_imp= gr_imp_L1*(ln_inv_es_id_elast_sum_mean+ln_inv_es_id_elast_sum_sd); /* ***************************************************************************** */ /* THIS (x_beta_6) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO THE ELASTICITY MEASURE */ predict x_beta_6; sum x_beta_6; /* ***************************************************************************** */ /* ** TABLE 2: Specification (2): Check on Baseline model, alternate definition of elasticities as = 1/(xs+id) ** */ /* ***************************************************************************** */ #delimit; clear; use "SETA_estim_final_05-01-2012.dta"; /* RESCALE VARIABLES */ replace gr_imp_L1=gr_imp_L1/10000; replace sd_imp_gr= sd_imp_gr/100; replace inv_es_id_elast_sum= inv_es_id_elast_sum/100; replace chg_rxr_L1= chg_rxr_L1/1000; *Generate the interacted continuous variables; gen MDXS_imp= inv_es_id_elast_sum*gr_imp_L1; *As a dprobit; dprobit AD_imposed gr_imp_L1 sd_imp_gr inv_es_id_elast_sum MDXS_imp chg_rxr_L1, robust; mfx compute; *As a probit, with interaction; probit AD_imposed gr_imp_L1 sd_imp_gr inv_es_id_elast_sum MDXS_imp chg_rxr_L1, robust; keep if e(sample)==1; sum AD_imposed gr_imp_L1 sd_imp_gr inv_es_id_elast_sum MDXS_imp chg_rxr_L1; *Calculate marginal effects; *To verify code, start by recreating dprobit coefficients; predict x_beta1, xb; egen av_xbeta1=mean(x_beta1); scalar phi1=normalden(av_xbeta1); scalar list phi1; matrix marg=phi1*e(b); matrix list marg; *Next, calculate the interaction terms we’re interested in; egen av_imp_gr=mean(gr_imp_L1); egen av_elast=mean(inv_es_id_elast_sum); gen me_imports= (_b[gr_imp_L1]+_b[MDXS_imp]*av_elast)*phi1; gen me_elast= (_b[inv_es_id_elast_sum]+_b[MDXS_imp]*av_imp_gr)*phi1; /* ***************************************************************************** */ /* THESE ARE THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum me_imports; sum me_elast; *Calculate std errors of marginal effects; *To verify code, start by recreating dprobit coefficients; *Note that when working with the probit command, “robust,” the vce matrix is robust and the associated std errors are the “robust” std errors from dprobit; *define the VCE matrix; matrix varcov=e(V); matrix list varcov; *extract the diagonal of the vce matrix; matrix vc_row=vecdiag(varcov); *construct a new matrix with zeros on the off-diagonal; matrix vc_diag=diag(vc_row); *take the square root of the diagonal elements; matrix std_err=cholesky(vc_diag); *scale up to marginal effects; matrix std_err_marg=phi1*std_err; matrix std_err_scaled=vecdiag(std_err_marg); matrix list std_err_scaled; matrix list varcov; gen var_me_imp =varcov[1,1]+(varcov[4,4]*(av_elast^2)) +2*av_elast*varcov[1,4]; gen sqrt_var_imp=var_me_imp^(.5); gen std_err_me_imp=sqrt_var_imp*phi1; gen var_me_elast=varcov[3,3] +(varcov[4,4]*(av_imp_gr^2))+2*av_imp_gr*varcov[3,4]; gen sqrt_var_elast=var_me_elast^(.5); gen std_err_me_elast=sqrt_var_elast*phi1; /* ***************************************************************************** */ /* THESE ARE THE STANDARD ERRORS OF THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum std_err_me_imp; sum std_err_me_elast; ************************************************************************************************; *PREDICTION: quantify the effect on the prob of a one std dev shock for interaction terms; ************************************************************************************************; *Calculate the predicted value at the mean of the dataset; predict x_beta_1; sum x_beta_1; *Generate local variables equal to the mean and std dev of gr_imp_L1; egen gr_imp_L1_mean= mean(gr_imp_L1); egen gr_imp_L1_sd=sd(gr_imp_L1); gen gr_imp_L1_saved=gr_imp_L1; replace gr_imp_L1= gr_imp_L1_mean + gr_imp_L1_sd; *Generate local variables equal to the mean and std dev of the elasticities; egen inv_es_id_elast_sum_mean= mean(inv_es_id_elast_sum); egen inv_es_id_elast_sum_sd=sd(inv_es_id_elast_sum); *Part 1: Consider the effect on the probability of a one std deviation shock to import growth; predict x_beta_2; sum x_beta_2; gen MDXS_imp_saved=MDXS_imp; replace MDXS_imp= inv_es_id_elast_sum*(gr_imp_L1_mean+gr_imp_L1_sd); /* ***************************************************************************** */ /* THIS (x_beta_3) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO IMP GROWTH */ predict x_beta_3; sum x_beta_3; *Part 2: Consider the effect of a one standard deviation shock to the elasticity measure; *First, change those values back to the means; replace gr_imp_L1=gr_imp_L1_saved; replace MDXS_imp=MDXS_imp_saved; /* ***************************************************************************** */ *Check that this (x_beta_4) is the same as x_beta_1 so the original data is reloaded into memory; predict x_beta_4; sum x_beta_4; replace inv_es_id_elast_sum= inv_es_id_elast_sum_mean + inv_es_id_elast_sum_sd; predict x_beta_5; sum x_beta_5; replace MDXS_imp= gr_imp_L1*(inv_es_id_elast_sum_mean+inv_es_id_elast_sum_sd); /* ***************************************************************************** */ /* THIS (x_beta_6) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO THE ELASTICITY MEASURE */ predict x_beta_6; sum x_beta_6; /* ***************************************************************************** */ /* ** TABLE 2: Specification (3): Baseline model, subsample after removing "outlier" XS and ID elasticities above and below 5% threshold ** */ /* ***************************************************************************** */ #delimit; clear; use "SETA_estim_final_05-01-2012.dta"; /* RESCALE VARIABLES */ replace gr_imp_L1=gr_imp_L1/10000; replace sd_imp_gr= sd_imp_gr/100; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum/1000; replace chg_rxr_L1= chg_rxr_L1/1000; *Generate the interacted continuous variables; gen MDXS_imp= ln_inv_es_id_elast_sum*gr_imp_L1; dprobit AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1, robust; keep if e(sample)==1; sum inv_id_elast_med, detail; drop if inv_id_elast_med>.810888 | inv_id_elast_med<.0922983; sum inv_es_elast_med, detail; drop if inv_es_elast_med>5.518096 | inv_es_elast_med<.0067208; *As a dprobit; dprobit AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1, robust; mfx compute; *As a probit, with interaction; probit AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1, robust; keep if e(sample)==1; sum AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1; *Calculate marginal effects; *To verify code, start by recreating dprobit coefficients; predict x_beta1, xb; egen av_xbeta1=mean(x_beta1); scalar phi1=normalden(av_xbeta1); scalar list phi1; matrix marg=phi1*e(b); matrix list marg; *Next, calculate the interaction terms we’re interested in; egen av_imp_gr=mean(gr_imp_L1); egen av_elast=mean(ln_inv_es_id_elast_sum); gen me_imports= (_b[gr_imp_L1]+_b[MDXS_imp]*av_elast)*phi1; gen me_elast= (_b[ln_inv_es_id_elast_sum]+_b[MDXS_imp]*av_imp_gr)*phi1; /* ***************************************************************************** */ /* THESE ARE THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum me_imports; sum me_elast; *Calculate std errors of marginal effects; *To verify code, start by recreating dprobit coefficients; *Note that when working with the probit command, “robust,” the vce matrix is robust and the associated std errors are the “robust” std errors from dprobit; *define the VCE matrix; matrix varcov=e(V); matrix list varcov; *extract the diagonal of the vce matrix; matrix vc_row=vecdiag(varcov); *construct a new matrix with zeros on the off-diagonal; matrix vc_diag=diag(vc_row); *take the square root of the diagonal elements; matrix std_err=cholesky(vc_diag); *scale up to marginal effects; matrix std_err_marg=phi1*std_err; matrix std_err_scaled=vecdiag(std_err_marg); matrix list std_err_scaled; matrix list varcov; gen var_me_imp =varcov[1,1]+(varcov[4,4]*(av_elast^2)) +2*av_elast*varcov[1,4]; gen sqrt_var_imp=var_me_imp^(.5); gen std_err_me_imp=sqrt_var_imp*phi1; gen var_me_elast=varcov[3,3] +(varcov[4,4]*(av_imp_gr^2))+2*av_imp_gr*varcov[3,4]; gen sqrt_var_elast=var_me_elast^(.5); gen std_err_me_elast=sqrt_var_elast*phi1; /* ***************************************************************************** */ /* THESE ARE THE STANDARD ERRORS OF THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum std_err_me_imp; sum std_err_me_elast; ************************************************************************************************; *PREDICTION: quantify the effect on the prob of a one std dev shock for interaction terms; ************************************************************************************************; *Calculate the predicted value at the mean of the dataset; predict x_beta_1; sum x_beta_1; *Generate local variables equal to the mean and std dev of gr_imp_L1; egen gr_imp_L1_mean= mean(gr_imp_L1); egen gr_imp_L1_sd=sd(gr_imp_L1); gen gr_imp_L1_saved=gr_imp_L1; replace gr_imp_L1= gr_imp_L1_mean + gr_imp_L1_sd; *Generate local variables equal to the mean and std dev of the elasticities; egen ln_inv_es_id_elast_sum_mean= mean(ln_inv_es_id_elast_sum); egen ln_inv_es_id_elast_sum_sd=sd(ln_inv_es_id_elast_sum); *Part 1: Consider the effect on the probability of a one std deviation shock to import growth; predict x_beta_2; sum x_beta_2; gen MDXS_imp_saved=MDXS_imp; replace MDXS_imp= ln_inv_es_id_elast_sum*(gr_imp_L1_mean+gr_imp_L1_sd); /* ***************************************************************************** */ /* THIS (x_beta_3) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO IMP GROWTH */ predict x_beta_3; sum x_beta_3; *Part 2: Consider the effect of a one standard deviation shock to the elasticity measure; *First, change those values back to the means; replace gr_imp_L1=gr_imp_L1_saved; replace MDXS_imp=MDXS_imp_saved; /* ***************************************************************************** */ *Check that this (x_beta_4) is the same as x_beta_1 so the original data is reloaded into memory; predict x_beta_4; sum x_beta_4; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum_mean + ln_inv_es_id_elast_sum_sd; predict x_beta_5; sum x_beta_5; replace MDXS_imp= gr_imp_L1*(ln_inv_es_id_elast_sum_mean+ln_inv_es_id_elast_sum_sd); /* ***************************************************************************** */ /* THIS (x_beta_6) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO THE ELASTICITY MEASURE */ predict x_beta_6; sum x_beta_6; /* ***************************************************************************** */ /* ** TABLE 2: Specification (4): Baseline model, Subsample on only the top 10 US import sources ** */ /* ***************************************************************************** */ clear; use "SETA_estim_final_05-01-2012.dta"; #delimit; keep if country=="Canada" | country=="Japan" | country=="Mexico" | country=="China" | country=="Germany" | country=="Taiwan" | country=="United Kingdom" | country=="South Korea" | country=="France" | country=="Italy" | country=="Malaysia" ; /* RESCALE VARIABLES */ replace gr_imp_L1=gr_imp_L1/10000; replace sd_imp_gr= sd_imp_gr/100; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum/1000; replace chg_rxr_L1= chg_rxr_L1/1000; *Generate the interacted continuous variables; gen MDXS_imp= ln_inv_es_id_elast_sum*gr_imp_L1; *As a dprobit; dprobit AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1, robust; mfx compute; *As a probit, with interaction; probit AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1, robust; keep if e(sample)==1; sum AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1; *Calculate marginal effects; *To verify code, start by recreating dprobit coefficients; predict x_beta1, xb; egen av_xbeta1=mean(x_beta1); scalar phi1=normalden(av_xbeta1); scalar list phi1; matrix marg=phi1*e(b); matrix list marg; *Next, calculate the interaction terms we’re interested in; egen av_imp_gr=mean(gr_imp_L1); egen av_elast=mean(ln_inv_es_id_elast_sum); gen me_imports= (_b[gr_imp_L1]+_b[MDXS_imp]*av_elast)*phi1; gen me_elast= (_b[ln_inv_es_id_elast_sum]+_b[MDXS_imp]*av_imp_gr)*phi1; /* ***************************************************************************** */ /* THESE ARE THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum me_imports; sum me_elast; *Calculate std errors of marginal effects; *To verify code, start by recreating dprobit coefficients; *Note that when working with the probit command, “robust,” the vce matrix is robust and the associated std errors are the “robust” std errors from dprobit; *define the VCE matrix; matrix varcov=e(V); matrix list varcov; *extract the diagonal of the vce matrix; matrix vc_row=vecdiag(varcov); *construct a new matrix with zeros on the off-diagonal; matrix vc_diag=diag(vc_row); *take the square root of the diagonal elements; matrix std_err=cholesky(vc_diag); *scale up to marginal effects; matrix std_err_marg=phi1*std_err; matrix std_err_scaled=vecdiag(std_err_marg); matrix list std_err_scaled; matrix list varcov; gen var_me_imp =varcov[1,1]+(varcov[4,4]*(av_elast^2)) +2*av_elast*varcov[1,4]; gen sqrt_var_imp=var_me_imp^(.5); gen std_err_me_imp=sqrt_var_imp*phi1; gen var_me_elast=varcov[3,3] +(varcov[4,4]*(av_imp_gr^2))+2*av_imp_gr*varcov[3,4]; gen sqrt_var_elast=var_me_elast^(.5); gen std_err_me_elast=sqrt_var_elast*phi1; /* ***************************************************************************** */ /* THESE ARE THE STANDARD ERRORS OF THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum std_err_me_imp; sum std_err_me_elast; ************************************************************************************************; *PREDICTION: quantify the effect on the prob of a one std dev shock for interaction terms; ************************************************************************************************; *Calculate the predicted value at the mean of the dataset; predict x_beta_1; sum x_beta_1; *Generate local variables equal to the mean and std dev of gr_imp_L1; egen gr_imp_L1_mean= mean(gr_imp_L1); egen gr_imp_L1_sd=sd(gr_imp_L1); gen gr_imp_L1_saved=gr_imp_L1; replace gr_imp_L1= gr_imp_L1_mean + gr_imp_L1_sd; *Generate local variables equal to the mean and std dev of the elasticities; egen ln_inv_es_id_elast_sum_mean= mean(ln_inv_es_id_elast_sum); egen ln_inv_es_id_elast_sum_sd=sd(ln_inv_es_id_elast_sum); *Part 1: Consider the effect on the probability of a one std deviation shock to import growth; predict x_beta_2; sum x_beta_2; gen MDXS_imp_saved=MDXS_imp; replace MDXS_imp= ln_inv_es_id_elast_sum*(gr_imp_L1_mean+gr_imp_L1_sd); /* ***************************************************************************** */ /* THIS (x_beta_3) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO IMP GROWTH */ predict x_beta_3; sum x_beta_3; *Part 2: Consider the effect of a one standard deviation shock to the elasticity measure; *First, change those values back to the means; replace gr_imp_L1=gr_imp_L1_saved; replace MDXS_imp=MDXS_imp_saved; /* ***************************************************************************** */ *Check that this (x_beta_4) is the same as x_beta_1 so the original data is reloaded into memory; predict x_beta_4; sum x_beta_4; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum_mean + ln_inv_es_id_elast_sum_sd; predict x_beta_5; sum x_beta_5; replace MDXS_imp= gr_imp_L1*(ln_inv_es_id_elast_sum_mean+ln_inv_es_id_elast_sum_sd); /* ***************************************************************************** */ /* THIS (x_beta_6) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO THE ELASTICITY MEASURE */ predict x_beta_6; sum x_beta_6; /* ***************************************************************************** */ /* ** TABLE 2: Specification (5): Baseline model, Top 10 trading partners, logit model with CGM multiway clustering ** */ /* ***************************************************************************** */ clear; use "SETA_estim_final_05-01-2012.dta"; #delimit; keep if country=="Canada" | country=="Japan" | country=="Mexico" | country=="China" | country=="Germany" | country=="Taiwan" | country=="United Kingdom" | country=="South Korea" | country=="France" | country=="Italy" | country=="Malaysia" ; /* RESCALE VARIABLES */ replace gr_imp_L1=gr_imp_L1/10000; replace sd_imp_gr= sd_imp_gr/100; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum/1000; replace chg_rxr_L1= chg_rxr_L1/1000; *Generate the interacted continuous variables; gen MDXS_imp= ln_inv_es_id_elast_sum*gr_imp_L1; *As a logit with interaction and multiway clustering; cgmlogit AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1, cluster(country NAICS); *calculate marginal effects; mfx compute; keep if e(sample)==1; sum AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1; *Calculate marginal effects; *To verify code, start by recreating mfx coefficients; predict x_beta1, xb; egen av_xbeta1=mean(x_beta1); scalar phi1= [ 1/(1+exp(-av_xbeta1)) ] *[1- (1/(1+exp(-av_xbeta1)))]; scalar list phi1; matrix marg=phi1*e(b); matrix list marg; *Next, calculate the interaction terms we’re interested in; egen av_imp_gr=mean(gr_imp_L1); egen av_elast=mean(ln_inv_es_id_elast_sum); gen me_imports= (_b[gr_imp_L1]+_b[MDXS_imp]*av_elast)*phi1; gen me_elast= (_b[ln_inv_es_id_elast_sum]+_b[MDXS_imp]*av_imp_gr)*phi1; /* ***************************************************************************** */ /* THESE ARE THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum me_imports; sum me_elast; *Calculate std errors of marginal effects; *define the VCE matrix; matrix varcov=e(V); matrix list varcov; *extract the diagonal of the vce matrix; matrix vc_row=vecdiag(varcov); *construct a new matrix with zeros on the off-diagonal; matrix vc_diag=diag(vc_row); *take the square root of the diagonal elements; matrix std_err=cholesky(vc_diag); *scale up to marginal effects; matrix std_err_marg=phi1*std_err; matrix std_err_scaled=vecdiag(std_err_marg); matrix list std_err_scaled; matrix list varcov; gen var_me_imp =varcov[1,1]+(varcov[4,4]*(av_elast^2)) +2*av_elast*varcov[1,4]; gen sqrt_var_imp=var_me_imp^(.5); gen std_err_me_imp=sqrt_var_imp*phi1; gen var_me_elast=varcov[3,3] +(varcov[4,4]*(av_imp_gr^2))+2*av_imp_gr*varcov[3,4]; gen sqrt_var_elast=var_me_elast^(.5); gen std_err_me_elast=sqrt_var_elast*phi1; /* ***************************************************************************** */ /* THESE ARE THE STANDARD ERRORS OF THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum std_err_me_imp; sum std_err_me_elast; ************************************************************************************************; *PREDICTION: quantify the effect on the prob of a one std dev shock for interaction terms; ************************************************************************************************; *Calculate the predicted value at the mean of the dataset; predict x_beta_1; sum x_beta_1; *Generate local variables equal to the mean and std dev of gr_imp_L1; egen gr_imp_L1_mean= mean(gr_imp_L1); egen gr_imp_L1_sd=sd(gr_imp_L1); gen gr_imp_L1_saved=gr_imp_L1; replace gr_imp_L1= gr_imp_L1_mean + gr_imp_L1_sd; *Generate local variables equal to the mean and std dev of the elasticities; egen ln_inv_es_id_elast_sum_mean= mean(ln_inv_es_id_elast_sum); egen ln_inv_es_id_elast_sum_sd=sd(ln_inv_es_id_elast_sum); *Part 1: Consider the effect on the probability of a one std deviation shock to import growth; predict x_beta_2; sum x_beta_2; gen MDXS_imp_saved=MDXS_imp; replace MDXS_imp= ln_inv_es_id_elast_sum*(gr_imp_L1_mean+gr_imp_L1_sd); /* ***************************************************************************** */ /* THIS (x_beta_3) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO IMP GROWTH */ predict x_beta_3; sum x_beta_3; *Part 2: Consider the effect of a one standard deviation shock to the elasticity measure; *First, change those values back to the means; replace gr_imp_L1=gr_imp_L1_saved; replace MDXS_imp=MDXS_imp_saved; /* ***************************************************************************** */ *Check that this (x_beta_4) is the same as x_beta_1 so the original data is reloaded into memory; predict x_beta_4; sum x_beta_4; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum_mean + ln_inv_es_id_elast_sum_sd; predict x_beta_5; sum x_beta_5; replace MDXS_imp= gr_imp_L1*(ln_inv_es_id_elast_sum_mean+ln_inv_es_id_elast_sum_sd); /* ***************************************************************************** */ /* THIS (x_beta_6) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO THE ELASTICITY MEASURE */ predict x_beta_6; sum x_beta_6; /* ***************************************************************************** */ /* ** TABLE 2: Alternative Specification (5): Baseline model, All trading partners, logit model with CGM multiway clustering ** */ /* ***************************************************************************** */ clear; use "SETA_estim_final_05-01-2012.dta"; /* RESCALE VARIABLES */ replace gr_imp_L1=gr_imp_L1/10000; replace sd_imp_gr= sd_imp_gr/100; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum/1000; replace chg_rxr_L1= chg_rxr_L1/1000; *Generate the interacted continuous variables; gen MDXS_imp= ln_inv_es_id_elast_sum*gr_imp_L1; *As a logit with interaction and multiway clustering; cgmlogit AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1, cluster(country NAICS); *calculate marginal effects; mfx compute; keep if e(sample)==1; sum AD_imposed gr_imp_L1 sd_imp_gr ln_inv_es_id_elast_sum MDXS_imp chg_rxr_L1; *Calculate marginal effects; *To verify code, start by recreating mfx coefficients; predict x_beta1, xb; egen av_xbeta1=mean(x_beta1); scalar phi1= [ 1/(1+exp(-av_xbeta1)) ] *[1- (1/(1+exp(-av_xbeta1)))]; scalar list phi1; matrix marg=phi1*e(b); matrix list marg; *Next, calculate the interaction terms we’re interested in; egen av_imp_gr=mean(gr_imp_L1); egen av_elast=mean(ln_inv_es_id_elast_sum); gen me_imports= (_b[gr_imp_L1]+_b[MDXS_imp]*av_elast)*phi1; gen me_elast= (_b[ln_inv_es_id_elast_sum]+_b[MDXS_imp]*av_imp_gr)*phi1; /* ***************************************************************************** */ /* THESE ARE THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum me_imports; sum me_elast; *Calculate std errors of marginal effects; *define the VCE matrix; matrix varcov=e(V); matrix list varcov; *extract the diagonal of the vce matrix; matrix vc_row=vecdiag(varcov); *construct a new matrix with zeros on the off-diagonal; matrix vc_diag=diag(vc_row); *take the square root of the diagonal elements; matrix std_err=cholesky(vc_diag); *scale up to marginal effects; matrix std_err_marg=phi1*std_err; matrix std_err_scaled=vecdiag(std_err_marg); matrix list std_err_scaled; matrix list varcov; gen var_me_imp =varcov[1,1]+(varcov[4,4]*(av_elast^2)) +2*av_elast*varcov[1,4]; gen sqrt_var_imp=var_me_imp^(.5); gen std_err_me_imp=sqrt_var_imp*phi1; gen var_me_elast=varcov[3,3] +(varcov[4,4]*(av_imp_gr^2))+2*av_imp_gr*varcov[3,4]; gen sqrt_var_elast=var_me_elast^(.5); gen std_err_me_elast=sqrt_var_elast*phi1; /* ***************************************************************************** */ /* THESE ARE THE STANDARD ERRORS OF THE MARGINAL EFFECTS ESTIMATES INCLUDING THE DIRECT AND INDIRECT EFFECTS FOR THE VARIABLES OF INTEREST */ sum std_err_me_imp; sum std_err_me_elast; ************************************************************************************************; *PREDICTION: quantify the effect on the prob of a one std dev shock for interaction terms; ************************************************************************************************; *Calculate the predicted value at the mean of the dataset; predict x_beta_1; sum x_beta_1; *Generate local variables equal to the mean and std dev of gr_imp_L1; egen gr_imp_L1_mean= mean(gr_imp_L1); egen gr_imp_L1_sd=sd(gr_imp_L1); gen gr_imp_L1_saved=gr_imp_L1; replace gr_imp_L1= gr_imp_L1_mean + gr_imp_L1_sd; *Generate local variables equal to the mean and std dev of the elasticities; egen ln_inv_es_id_elast_sum_mean= mean(ln_inv_es_id_elast_sum); egen ln_inv_es_id_elast_sum_sd=sd(ln_inv_es_id_elast_sum); *Part 1: Consider the effect on the probability of a one std deviation shock to import growth; predict x_beta_2; sum x_beta_2; gen MDXS_imp_saved=MDXS_imp; replace MDXS_imp= ln_inv_es_id_elast_sum*(gr_imp_L1_mean+gr_imp_L1_sd); /* ***************************************************************************** */ /* THIS (x_beta_3) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO IMP GROWTH */ predict x_beta_3; sum x_beta_3; *Part 2: Consider the effect of a one standard deviation shock to the elasticity measure; *First, change those values back to the means; replace gr_imp_L1=gr_imp_L1_saved; replace MDXS_imp=MDXS_imp_saved; /* ***************************************************************************** */ *Check that this (x_beta_4) is the same as x_beta_1 so the original data is reloaded into memory; predict x_beta_4; sum x_beta_4; replace ln_inv_es_id_elast_sum= ln_inv_es_id_elast_sum_mean + ln_inv_es_id_elast_sum_sd; predict x_beta_5; sum x_beta_5; replace MDXS_imp= gr_imp_L1*(ln_inv_es_id_elast_sum_mean+ln_inv_es_id_elast_sum_sd); /* ***************************************************************************** */ /* THIS (x_beta_6) IS THE FULL INTERRACTED EFFECT ON THE PROBABILITY OF A ONE STD DEV INCREASE TO THE ELASTICITY MEASURE */ predict x_beta_6; sum x_beta_6; log close;