Hi all,
I am currently writing my bachelor's thesis, where I am trying to quantify the impact of the creation of the euro on intra-EU and extra-EU trade. I have obtained data from CEPII Gravity and Tradeprod databases, and am using An Advanced Guide to Trade Policy Analysis: The Structural Gravity Model to structure my gravity equation.
I am getting stuck when trying to generate country-pair fixed effects
. * STATA commands to estimate gravity model with the country-pair fixed effects:
. egen pair_id = group(iso3num_o iso3num_d)
. tabulate pair_id, generate(PAIR_FE)
too many values
I have attempted to use ppmlhdfe after looking at similar forum posts, but when I do that, my euro country dummy variable is omitted. I will attach both the code not using ppml and using ppml below. Any help would be greatly appreciated!
1. get stuck at country pair fixed effects
clear all
set more off
clear matrix
ssc install ppml
// Close the existing log file
log close
// Start a new log file
log using "/Users/alicelunt/Desktop/stata_thesis/my_analysis.log", replace
cd "/Users/alicelunt/Desktop/stata_thesis"
use "/Users/alicelunt/Desktop/stata_thesis/Gravity_dta_V202102/Gravity_V202102.dta", clear
* merge files
keep if year >= 1966
keep if year <= 2018
keep iso3num_o iso3num_d year dist contig comlang_off comcol rta eu_d eu_o wto_o wto_d gatt_o gatt_d tradeflow_comtrade_o tradeflow_comtrade_d
merge 1:m iso3num_o iso3num_d year using "/Users/alicelunt/Desktop/stata_thesis/TPe_V202201.dta"
keep if _m==3
drop _m
* Analysis considers panel data with 4 year interval (1986, 1990, ..., 2018)
keep if year == 1986 | year == 1990 | year == 1994 | year == 1998 | year == 2002 | year == 2006 | year == 2010 | year == 2014 | year == 2018
* create pair id for merged data
* gen pair_id = iso3num_o * 1000 + iso3num_d
* Create the dependent variable
generate ln_trade = ln(tradeflow_comtrade_o)
* Create the independent variables
generate ln_DIST = ln(dist)
* Create exporter-time fixed effects
egen exp_time = group(iso3num_o year)
quietly tabulate exp_time, gen(EXPORTER_TIME_FE)
* Create importer-time fixed effects
egen imp_time = group(iso3num_d year)
quietly tabulate imp_time, gen(IMPORTER_TIME_FE)
* STATA commands to estimate gravity model with the country-pair fixed effects:
egen pair_id = group(iso3num_o iso3num_d)
quietly tabulate pair_id, generate(PAIR_FE)
// Define the Euro countries and the years they entered
gen euro_country = 0
// Austria (4), Belgium (56), Finland (246), France (250), Germany (276), Ireland (372), Italy (380), Luxembourg (442), Netherlands (528), Portugal (620), Spain (724) joined on 1 Jan 1999
replace euro_country = 1 if iso3num_o == 40 & year >= 1999
replace euro_country = 1 if iso3num_o == 56 & year >= 1999
replace euro_country = 1 if iso3num_o == 246 & year >= 1999
replace euro_country = 1 if iso3num_o == 250 & year >= 1999
replace euro_country = 1 if iso3num_o == 276 & year >= 1999
replace euro_country = 1 if iso3num_o == 372 & year >= 1999
replace euro_country = 1 if iso3num_o == 380 & year >= 1999
replace euro_country = 1 if iso3num_o == 442 & year >= 1999
replace euro_country = 1 if iso3num_o == 528 & year >= 1999
replace euro_country = 1 if iso3num_o == 620 & year >= 1999
replace euro_country = 1 if iso3num_o == 724 & year >= 1999
// Greece (300) joined in 2001
replace euro_country = 1 if iso3num_o == 300 & year >= 2001
// Slovenia (705) joined in 2007
replace euro_country = 1 if iso3num_o == 705 & year >= 2007
// Cyprus (196) and Malta (470) joined in 2008
replace euro_country = 1 if iso3num_o == 196 & year >= 2008
replace euro_country = 1 if iso3num_o == 470 & year >= 2008
// Slovakia (703) joined in 2009
replace euro_country = 1 if iso3num_o == 703 & year >= 2009
// Estonia (233) joined in 2011
replace euro_country = 1 if iso3num_o == 233 & year >= 2011
// Latvia (428) joined in 2014
replace euro_country = 1 if iso3num_o == 428 & year >= 2014
// Lithuania (440) joined in 2015
replace euro_country = 1 if iso3num_o == 440 & year >= 2015
// Label the variable for clarity
label variable euro_country "Euro country (1=yes)"
// Estimate the gravity model and store the results
regress ln_trade exp_time* imp_time* ln_DIST contig comlang_off euro_country if iso3num_o != iso3num_d, cluster(pair_id)
estimates store fes1
// close the log file
log close
2. euro_country variable dropped
clear all
set more off
clear matrix
ssc install ppml
ssc install ppmlhdfe
ssc install reghdfe
// Close the existing log file
*log close
// Start a new log file
log using "/Users/alicelunt/Desktop/stata_thesis/my_analysis.log", replace
cd "/Users/alicelunt/Desktop/stata_thesis"
use "/Users/alicelunt/Desktop/stata_thesis/Gravity_dta_V202102/Gravity_V202102.dta", clear
* merge files
keep if year >= 1966
keep if year <= 2018
keep iso3num_o iso3num_d year dist contig comlang_off comcol rta eu_d eu_o wto_o wto_d gatt_o gatt_d tradeflow_comtrade_o tradeflow_comtrade_d
merge 1:m iso3num_o iso3num_d year using "/Users/alicelunt/Desktop/stata_thesis/TPe_V202201.dta"
keep if _m==3
drop _m
* Analysis considers panel data with 4 year interval (1986, 1990, ..., 2018)
keep if year == 1986 | year == 1990 | year == 1994 | year == 1998 | year == 2002 | year == 2006 | year == 2010 | year == 2014 | year == 2018
* create pair id for merged data
* gen pair_id = iso3num_o * 1000 + iso3num_d
* Create the dependent variable
* generate ln_trade = ln(tradeflow_comtrade_o)
* Create the independent variables
generate ln_DIST = ln(dist)
// Define the Euro countries and the years they entered
gen euro_country = 0
// Austria (4), Belgium (56), Finland (246), France (250), Germany (276), Ireland (372), Italy (380), Luxembourg (442), Netherlands (528), Portugal (620), Spain (724) joined on 1 Jan 1999
replace euro_country = 1 if iso3num_o == 40 & year >= 1999
replace euro_country = 1 if iso3num_o == 56 & year >= 1999
replace euro_country = 1 if iso3num_o == 246 & year >= 1999
replace euro_country = 1 if iso3num_o == 250 & year >= 1999
replace euro_country = 1 if iso3num_o == 276 & year >= 1999
replace euro_country = 1 if iso3num_o == 372 & year >= 1999
replace euro_country = 1 if iso3num_o == 380 & year >= 1999
replace euro_country = 1 if iso3num_o == 442 & year >= 1999
replace euro_country = 1 if iso3num_o == 528 & year >= 1999
replace euro_country = 1 if iso3num_o == 620 & year >= 1999
replace euro_country = 1 if iso3num_o == 724 & year >= 1999
// Greece (300) joined in 2001
replace euro_country = 1 if iso3num_o == 300 & year >= 2001
// Slovenia (705) joined in 2007
replace euro_country = 1 if iso3num_o == 705 & year >= 2007
// Cyprus (196) and Malta (470) joined in 2008
replace euro_country = 1 if iso3num_o == 196 & year >= 2008
replace euro_country = 1 if iso3num_o == 470 & year >= 2008
// Slovakia (703) joined in 2009
replace euro_country = 1 if iso3num_o == 703 & year >= 2009
// Estonia (233) joined in 2011
replace euro_country = 1 if iso3num_o == 233 & year >= 2011
// Latvia (428) joined in 2014
replace euro_country = 1 if iso3num_o == 428 & year >= 2014
// Lithuania (440) joined in 2015
replace euro_country = 1 if iso3num_o == 440 & year >= 2015
// Estimate the gravity model and store the results
ppmlhdfe tradeflow_comtrade_o ln_DIST contig comlang_off euro_country if iso3num_o != iso3num_d, absorb(i.iso3num_d##i.year i.iso3num_o##i.year) cluster(iso3num_d#iso3num_o)
// close the log file
log close
Thanks again!
I am currently writing my bachelor's thesis, where I am trying to quantify the impact of the creation of the euro on intra-EU and extra-EU trade. I have obtained data from CEPII Gravity and Tradeprod databases, and am using An Advanced Guide to Trade Policy Analysis: The Structural Gravity Model to structure my gravity equation.
I am getting stuck when trying to generate country-pair fixed effects
. * STATA commands to estimate gravity model with the country-pair fixed effects:
. egen pair_id = group(iso3num_o iso3num_d)
. tabulate pair_id, generate(PAIR_FE)
too many values
I have attempted to use ppmlhdfe after looking at similar forum posts, but when I do that, my euro country dummy variable is omitted. I will attach both the code not using ppml and using ppml below. Any help would be greatly appreciated!
1. get stuck at country pair fixed effects
clear all
set more off
clear matrix
ssc install ppml
// Close the existing log file
log close
// Start a new log file
log using "/Users/alicelunt/Desktop/stata_thesis/my_analysis.log", replace
cd "/Users/alicelunt/Desktop/stata_thesis"
use "/Users/alicelunt/Desktop/stata_thesis/Gravity_dta_V202102/Gravity_V202102.dta", clear
* merge files
keep if year >= 1966
keep if year <= 2018
keep iso3num_o iso3num_d year dist contig comlang_off comcol rta eu_d eu_o wto_o wto_d gatt_o gatt_d tradeflow_comtrade_o tradeflow_comtrade_d
merge 1:m iso3num_o iso3num_d year using "/Users/alicelunt/Desktop/stata_thesis/TPe_V202201.dta"
keep if _m==3
drop _m
* Analysis considers panel data with 4 year interval (1986, 1990, ..., 2018)
keep if year == 1986 | year == 1990 | year == 1994 | year == 1998 | year == 2002 | year == 2006 | year == 2010 | year == 2014 | year == 2018
* create pair id for merged data
* gen pair_id = iso3num_o * 1000 + iso3num_d
* Create the dependent variable
generate ln_trade = ln(tradeflow_comtrade_o)
* Create the independent variables
generate ln_DIST = ln(dist)
* Create exporter-time fixed effects
egen exp_time = group(iso3num_o year)
quietly tabulate exp_time, gen(EXPORTER_TIME_FE)
* Create importer-time fixed effects
egen imp_time = group(iso3num_d year)
quietly tabulate imp_time, gen(IMPORTER_TIME_FE)
* STATA commands to estimate gravity model with the country-pair fixed effects:
egen pair_id = group(iso3num_o iso3num_d)
quietly tabulate pair_id, generate(PAIR_FE)
// Define the Euro countries and the years they entered
gen euro_country = 0
// Austria (4), Belgium (56), Finland (246), France (250), Germany (276), Ireland (372), Italy (380), Luxembourg (442), Netherlands (528), Portugal (620), Spain (724) joined on 1 Jan 1999
replace euro_country = 1 if iso3num_o == 40 & year >= 1999
replace euro_country = 1 if iso3num_o == 56 & year >= 1999
replace euro_country = 1 if iso3num_o == 246 & year >= 1999
replace euro_country = 1 if iso3num_o == 250 & year >= 1999
replace euro_country = 1 if iso3num_o == 276 & year >= 1999
replace euro_country = 1 if iso3num_o == 372 & year >= 1999
replace euro_country = 1 if iso3num_o == 380 & year >= 1999
replace euro_country = 1 if iso3num_o == 442 & year >= 1999
replace euro_country = 1 if iso3num_o == 528 & year >= 1999
replace euro_country = 1 if iso3num_o == 620 & year >= 1999
replace euro_country = 1 if iso3num_o == 724 & year >= 1999
// Greece (300) joined in 2001
replace euro_country = 1 if iso3num_o == 300 & year >= 2001
// Slovenia (705) joined in 2007
replace euro_country = 1 if iso3num_o == 705 & year >= 2007
// Cyprus (196) and Malta (470) joined in 2008
replace euro_country = 1 if iso3num_o == 196 & year >= 2008
replace euro_country = 1 if iso3num_o == 470 & year >= 2008
// Slovakia (703) joined in 2009
replace euro_country = 1 if iso3num_o == 703 & year >= 2009
// Estonia (233) joined in 2011
replace euro_country = 1 if iso3num_o == 233 & year >= 2011
// Latvia (428) joined in 2014
replace euro_country = 1 if iso3num_o == 428 & year >= 2014
// Lithuania (440) joined in 2015
replace euro_country = 1 if iso3num_o == 440 & year >= 2015
// Label the variable for clarity
label variable euro_country "Euro country (1=yes)"
// Estimate the gravity model and store the results
regress ln_trade exp_time* imp_time* ln_DIST contig comlang_off euro_country if iso3num_o != iso3num_d, cluster(pair_id)
estimates store fes1
// close the log file
log close
2. euro_country variable dropped
clear all
set more off
clear matrix
ssc install ppml
ssc install ppmlhdfe
ssc install reghdfe
// Close the existing log file
*log close
// Start a new log file
log using "/Users/alicelunt/Desktop/stata_thesis/my_analysis.log", replace
cd "/Users/alicelunt/Desktop/stata_thesis"
use "/Users/alicelunt/Desktop/stata_thesis/Gravity_dta_V202102/Gravity_V202102.dta", clear
* merge files
keep if year >= 1966
keep if year <= 2018
keep iso3num_o iso3num_d year dist contig comlang_off comcol rta eu_d eu_o wto_o wto_d gatt_o gatt_d tradeflow_comtrade_o tradeflow_comtrade_d
merge 1:m iso3num_o iso3num_d year using "/Users/alicelunt/Desktop/stata_thesis/TPe_V202201.dta"
keep if _m==3
drop _m
* Analysis considers panel data with 4 year interval (1986, 1990, ..., 2018)
keep if year == 1986 | year == 1990 | year == 1994 | year == 1998 | year == 2002 | year == 2006 | year == 2010 | year == 2014 | year == 2018
* create pair id for merged data
* gen pair_id = iso3num_o * 1000 + iso3num_d
* Create the dependent variable
* generate ln_trade = ln(tradeflow_comtrade_o)
* Create the independent variables
generate ln_DIST = ln(dist)
// Define the Euro countries and the years they entered
gen euro_country = 0
// Austria (4), Belgium (56), Finland (246), France (250), Germany (276), Ireland (372), Italy (380), Luxembourg (442), Netherlands (528), Portugal (620), Spain (724) joined on 1 Jan 1999
replace euro_country = 1 if iso3num_o == 40 & year >= 1999
replace euro_country = 1 if iso3num_o == 56 & year >= 1999
replace euro_country = 1 if iso3num_o == 246 & year >= 1999
replace euro_country = 1 if iso3num_o == 250 & year >= 1999
replace euro_country = 1 if iso3num_o == 276 & year >= 1999
replace euro_country = 1 if iso3num_o == 372 & year >= 1999
replace euro_country = 1 if iso3num_o == 380 & year >= 1999
replace euro_country = 1 if iso3num_o == 442 & year >= 1999
replace euro_country = 1 if iso3num_o == 528 & year >= 1999
replace euro_country = 1 if iso3num_o == 620 & year >= 1999
replace euro_country = 1 if iso3num_o == 724 & year >= 1999
// Greece (300) joined in 2001
replace euro_country = 1 if iso3num_o == 300 & year >= 2001
// Slovenia (705) joined in 2007
replace euro_country = 1 if iso3num_o == 705 & year >= 2007
// Cyprus (196) and Malta (470) joined in 2008
replace euro_country = 1 if iso3num_o == 196 & year >= 2008
replace euro_country = 1 if iso3num_o == 470 & year >= 2008
// Slovakia (703) joined in 2009
replace euro_country = 1 if iso3num_o == 703 & year >= 2009
// Estonia (233) joined in 2011
replace euro_country = 1 if iso3num_o == 233 & year >= 2011
// Latvia (428) joined in 2014
replace euro_country = 1 if iso3num_o == 428 & year >= 2014
// Lithuania (440) joined in 2015
replace euro_country = 1 if iso3num_o == 440 & year >= 2015
// Estimate the gravity model and store the results
ppmlhdfe tradeflow_comtrade_o ln_DIST contig comlang_off euro_country if iso3num_o != iso3num_d, absorb(i.iso3num_d##i.year i.iso3num_o##i.year) cluster(iso3num_d#iso3num_o)
// close the log file
log close
Thanks again!
Comment