Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • country_year fixed effects and product fixed effects

    Hi all,
    I was wondering whether someone could help me set up a code to regress my data using OLS-Fixed effects. I want to control for both Destination-year effect and product effects. Destination-year because of controlling for multilateral resistance terms and product effects because controlling for this allows to isolate the effect of distance and other location-specific variables.

    I already wrote these codes only considering the Destination-year effects, but I have problems with them both:

    First one:

    Code:
    egen Destid = group(Destination)
    tab(year), gen(year_)
    tab(Destid), gen(Destid_)
    reg ln_trade ln_dist ln_pop ln_gdp ln_tariff ln_Tech ln_NonTech rta comlang_off comrelig contig Destid_* year_*
    Second one:

    Code:
    egen Destid = group(Destination)
    tab(year), gen(year_)
    tab(Destid), gen(Destid_)
    egen country_pair = group(year Destid)
    xtreg ln_trade ln_dist ln_pop ln_gdp ln_tariff ln_Tech ln_NonTech rta comlang_off comrelig contig Destid_* year_*, fe robust
    With the 1st code, the problem is that in the output, variables such as distance and gdp aren't omitted. However, this should be the case since it's constant over all the year for each combination of year Origin and Destination?
    With the 2nd code, all these variables that I want to be omitted are omitted. But my supervisor told me that the code isn't correct since I didn't use xtset before xtreg. If I do this: xtset year Destid, I get an error saying "repeated time values within panel".

    Below I provided two subsets of my data, because the dataset is too large.

    Is there someone who could help me out?

    Thank you in advance!


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str32 Destination int year str9 Origin str6 HS1992 float(ln_trade ln_dist ln_pop ln_gdp ln_tariff ln_Tech ln_NonTech) byte contig float(comrelig comlang_off) byte rta
    "AUS" 1997 "JPN" "010111"         0 8.960981 21.571203 42.07983 0         0 0 0 .003891 0 0
    "AUS" 1998 "JPN" "010111"  6.792021 8.960981  21.58415 41.89326 0  .6931472 0 0 .003891 0 0
    "AUS" 1999 "JPN" "010111"   8.24438 8.960981 21.597475 41.99055 0 1.0986123 0 0 .003891 0 0
    "AUS" 2000 "JPN" "010111"  7.444451 8.960981 21.611134  42.1212 0 1.0986123 0 0 .003891 0 0
    "AUS" 2001 "JPN" "010111"   6.65124 8.960981 21.626814 41.90044 0 1.0986123 0 0 .003891 0 0
    "AUS" 2002 "JPN" "010111"  5.547499 8.960981 21.641344 41.89725 0 1.0986123 0 0 .003891 0 0
    "AUS" 2003 "JPN" "010111"  7.964765 8.960981 21.655825 42.14323 0 1.0986123 0 0 .003891 0 0
    "AUS" 2004 "JPN" "010111"  3.889716 8.960981 21.667753 42.49504 0 1.0986123 0 0 .003891 0 0
    "AUS" 2005 "JPN" "010111"  7.661951 8.960981 21.681046 42.60022 0 1.0986123 0 0 .003891 0 0
    "AUS" 2006 "JPN" "010111"  7.902208 8.960981 21.695665 42.62684 0 1.0986123 0 0 .003891 0 0
    "AUS" 2007 "JPN" "010111"  7.876872 8.960981 21.702026 42.75969 0 1.0986123 0 0 .003891 0 0
    "AUS" 2008 "JPN" "010111"         0 8.960981 21.721546 43.07891 0 1.3862944 0 0 .003891 0 0
    "AUS" 2009 "JPN" "010111"         0 8.960981  21.74101  42.9864 0  1.609438 0 0 .003891 0 0
    "AUS" 2010 "JPN" "010111"         0 8.960981 21.755726 43.28258 0  1.609438 0 0 .003891 0 0
    "AUS" 2011 "JPN" "010111"         0 8.960981  21.77249 43.55035 0  1.609438 0 0 .003891 0 0
    "AUS" 2012 "JPN" "010111"         0 8.960981 21.787527 43.65883 0  1.609438 0 0 .003891 0 0
    "AUS" 2013 "JPN" "010111"         0 8.960981  21.80353 43.48468 0  1.609438 0 0 .003891 0 0
    "AUS" 2014 "JPN" "010111"         0 8.960981 21.817194 43.40341 0  1.609438 0 0 .003891 0 0
    "AUS" 2015 "JPN" "010111"  6.581553 8.960981 21.830044 43.22096 0  1.609438 0 0 .003891 0 1
    "AUS" 2016 "JPN" "010111"  7.106945 8.960981  21.84299 43.22993 0  1.609438 0 0 .003891 0 1
    "AUS" 2017 "JPN" "010111"  9.136545 8.960981  21.86083 43.32487 0 1.7917595 0 0 .003891 0 1
    "AUS" 2018 "JPN" "010111"  9.291677 8.960981 21.874166 43.41997 0 1.7917595 0 0 .003891 0 1
    "AUS" 2019 "JPN" "010111"  9.591511 8.960981 21.887293   43.416 0 1.7917595 0 0 .003891 0 1
    "AUS" 2020 "JPN" "010111"  6.343467 9.006509 21.896477 43.35101 . 1.7917595 0 0 .003891 0 1
    "AUS" 2021 "JPN" "010111"  9.272713 8.960981  21.89529 43.48405 0   1.94591 0 0 .003891 0 1
    "AUS" 1997 "JPN" "010119"         0 8.960981 21.571203 42.07983 0         0 0 0 .003891 0 0
    "AUS" 1998 "JPN" "010119"  6.822485 8.960981  21.58415 41.89326 0  .6931472 0 0 .003891 0 0
    "AUS" 1999 "JPN" "010119"  5.307277 8.960981 21.597475 41.99055 0 1.0986123 0 0 .003891 0 0
    "AUS" 2000 "JPN" "010119"  6.287604 8.960981 21.611134  42.1212 0 1.0986123 0 0 .003891 0 0
    "AUS" 2001 "JPN" "010119"  5.216359 8.960981 21.626814 41.90044 0 1.0986123 0 0 .003891 0 0
    "AUS" 2002 "JPN" "010119"         0 8.960981 21.641344 41.89725 0 1.0986123 0 0 .003891 0 0
    "AUS" 2003 "JPN" "010119"         0 8.960981 21.655825 42.14323 0 1.0986123 0 0 .003891 0 0
    "AUS" 2004 "JPN" "010119" .55100745 8.960981 21.667753 42.49504 0 1.0986123 0 0 .003891 0 0
    "AUS" 2005 "JPN" "010119"  4.384486 8.960981 21.681046 42.60022 0 1.0986123 0 0 .003891 0 0
    "AUS" 2006 "JPN" "010119"  5.580009 8.960981 21.695665 42.62684 0 1.0986123 0 0 .003891 0 0
    "AUS" 2007 "JPN" "010119"  5.732473 8.960981 21.702026 42.75969 0 1.0986123 0 0 .003891 0 0
    "AUS" 2008 "JPN" "010119"         0 8.960981 21.721546 43.07891 0 1.3862944 0 0 .003891 0 0
    "AUS" 2009 "JPN" "010119"         0 8.960981  21.74101  42.9864 0  1.609438 0 0 .003891 0 0
    "AUS" 2010 "JPN" "010119"   5.14933 8.960981 21.755726 43.28258 0  1.609438 0 0 .003891 0 0
    "AUS" 2011 "JPN" "010119"         0 8.960981  21.77249 43.55035 0  1.609438 0 0 .003891 0 0
    "AUS" 2012 "JPN" "010119"         0 8.960981 21.787527 43.65883 0  1.609438 0 0 .003891 0 0
    "AUS" 2013 "JPN" "010119"         0 8.960981  21.80353 43.48468 0  1.609438 0 0 .003891 0 0
    "AUS" 2014 "JPN" "010119"  2.779378 8.960981 21.817194 43.40341 0  1.609438 0 0 .003891 0 0
    "AUS" 2015 "JPN" "010119"  8.188037 8.960981 21.830044 43.22096 0  1.609438 0 0 .003891 0 1
    "AUS" 2016 "JPN" "010119"  7.286732 8.960981  21.84299 43.22993 0  1.609438 0 0 .003891 0 1
    "AUS" 2017 "JPN" "010119"  8.460649 8.960981  21.86083 43.32487 0 1.7917595 0 0 .003891 0 1
    "AUS" 2018 "JPN" "010119"  8.031148 8.960981 21.874166 43.41997 0 1.7917595 0 0 .003891 0 1
    "AUS" 2019 "JPN" "010119"  7.817092 8.960981 21.887293   43.416 0 1.7917595 0 0 .003891 0 1
    "AUS" 2020 "JPN" "010119"  6.068285 9.006509 21.896477 43.35101 0 1.7917595 0 0 .003891 0 1
    "AUS" 2021 "JPN" "010119"  6.857221 8.960981  21.89529 43.48405 0   1.94591 0 0 .003891 0 1
    "AUS" 1997 "JPN" "010120"         0 8.960981 21.571203 42.07983 0         0 0 0 .003891 0 0
    "AUS" 1998 "JPN" "010120"         . 8.960981  21.58415 41.89326 .  .6931472 0 0 .003891 0 0
    "AUS" 1999 "JPN" "010120"         0 8.960981 21.597475 41.99055 0 1.0986123 0 0 .003891 0 0
    "AUS" 2001 "JPN" "010120"         0 8.960981 21.626814 41.90044 0 1.0986123 0 0 .003891 0 0
    "AUS" 2008 "JPN" "010120"         . 8.960981 21.721546 43.07891 . 1.3862944 0 0 .003891 0 0
    "AUS" 2009 "JPN" "010120"         . 8.960981  21.74101  42.9864 .  1.609438 0 0 .003891 0 0
    "AUS" 2014 "JPN" "010120"  5.803643 8.960981 21.817194 43.40341 .  1.609438 0 0 .003891 0 0
    "AUS" 2017 "JPN" "010120"         . 8.960981  21.86083 43.32487 . 1.7917595 0 0 .003891 0 1
    "AUS" 2021 "JPN" "010120"         . 8.960981  21.89529 43.48405 .   1.94591 0 0 .003891 0 1
    "AUS" 1997 "JPN" "010210"         0 8.960981 21.571203 42.07983 0  .6931472 0 0 .003891 0 0
    "AUS" 1998 "JPN" "010210"         0 8.960981  21.58415 41.89326 0  .6931472 0 0 .003891 0 0
    "AUS" 1999 "JPN" "010210"         0 8.960981 21.597475 41.99055 0 1.0986123 0 0 .003891 0 0
    "AUS" 2001 "JPN" "010210"         0 8.960981 21.626814 41.90044 0 1.0986123 0 0 .003891 0 0
    "AUS" 2002 "JPN" "010210"         0 8.960981 21.641344 41.89725 0 1.0986123 0 0 .003891 0 0
    "AUS" 2003 "JPN" "010210"         0 8.960981 21.655825 42.14323 0 1.0986123 0 0 .003891 0 0
    "AUS" 2010 "JPN" "010210"         . 8.960981 21.755726 43.28258 . 1.3862944 0 0 .003891 0 0
    "AUS" 2017 "JPN" "010210"         . 8.960981  21.86083 43.32487 .  1.609438 0 0 .003891 0 1
    "AUS" 2019 "JPN" "010210"         . 8.960981 21.887293   43.416 . 1.7917595 0 0 .003891 0 1
    "AUS" 2021 "JPN" "010210"         . 8.960981  21.89529 43.48405 .   1.94591 0 0 .003891 0 1
    "AUS" 1997 "JPN" "010290"         . 8.960981 21.571203 42.07983 .  .6931472 0 0 .003891 0 0
    "AUS" 1999 "JPN" "010290"         . 8.960981 21.597475 41.99055 . 1.0986123 0 0 .003891 0 0
    "AUS" 2000 "JPN" "010290"         0 8.960981 21.611134  42.1212 0 1.0986123 0 0 .003891 0 0
    "AUS" 2001 "JPN" "010290"         0 8.960981 21.626814 41.90044 0 1.0986123 0 0 .003891 0 0
    "AUS" 2004 "JPN" "010290"         0 8.960981 21.667753 42.49504 0 1.0986123 0 0 .003891 0 0
    "AUS" 2010 "JPN" "010290"         . 8.960981 21.755726 43.28258 . 1.3862944 0 0 .003891 0 0
    "AUS" 2017 "JPN" "010290"         . 8.960981  21.86083 43.32487 .  1.609438 0 0 .003891 0 1
    "AUS" 2019 "JPN" "010290"         . 8.960981 21.887293   43.416 . 1.7917595 0 0 .003891 0 1
    "AUS" 2021 "JPN" "010290"         . 8.960981  21.89529 43.48405 .   1.94591 0 0 .003891 0 1
    "AUS" 1999 "JPN" "010310"         . 8.960981 21.597475 41.99055 .  .6931472 0 0 .003891 0 0
    "AUS" 2001 "JPN" "010310"         . 8.960981 21.626814 41.90044 . 1.0986123 0 0 .003891 0 0
    "AUS" 2017 "JPN" "010310"         . 8.960981  21.86083 43.32487 . 1.3862944 0 0 .003891 0 1
    "AUS" 2021 "JPN" "010310"         . 8.960981  21.89529 43.48405 .  1.609438 0 0 .003891 0 1
    "AUS" 1999 "JPN" "010391"         . 8.960981 21.597475 41.99055 .  .6931472 0 0 .003891 0 0
    "AUS" 2001 "JPN" "010391"         . 8.960981 21.626814 41.90044 . 1.0986123 0 0 .003891 0 0
    "AUS" 2017 "JPN" "010391"         . 8.960981  21.86083 43.32487 . 1.3862944 0 0 .003891 0 1
    "AUS" 2021 "JPN" "010391"         . 8.960981  21.89529 43.48405 .  1.609438 0 0 .003891 0 1
    "AUS" 1999 "JPN" "010392"         . 8.960981 21.597475 41.99055 .  .6931472 0 0 .003891 0 0
    "AUS" 2001 "JPN" "010392"         . 8.960981 21.626814 41.90044 . 1.0986123 0 0 .003891 0 0
    "AUS" 2017 "JPN" "010392"         . 8.960981  21.86083 43.32487 . 1.3862944 0 0 .003891 0 1
    "AUS" 2021 "JPN" "010392"         . 8.960981  21.89529 43.48405 .  1.609438 0 0 .003891 0 1
    "AUS" 1999 "JPN" "010410"         . 8.960981 21.597475 41.99055 .  .6931472 0 0 .003891 0 0
    "AUS" 2001 "JPN" "010410"         0 8.960981 21.626814 41.90044 0  .6931472 0 0 .003891 0 0
    "AUS" 2006 "JPN" "010410"         0 8.960981 21.695665 42.62684 0  .6931472 0 0 .003891 0 0
    "AUS" 2007 "JPN" "010410"         0 8.960981 21.702026 42.75969 0  .6931472 0 0 .003891 0 0
    "AUS" 2008 "JPN" "010410"         0 8.960981 21.721546 43.07891 0  .6931472 0 0 .003891 0 0
    "AUS" 2009 "JPN" "010410"         0 8.960981  21.74101  42.9864 0  .6931472 0 0 .003891 0 0
    "AUS" 2010 "JPN" "010410"         0 8.960981 21.755726 43.28258 0  .6931472 0 0 .003891 0 0
    "AUS" 2011 "JPN" "010410"         0 8.960981  21.77249 43.55035 0  .6931472 0 0 .003891 0 0
    "AUS" 2012 "JPN" "010410"         0 8.960981 21.787527 43.65883 0  .6931472 0 0 .003891 0 0
    "AUS" 2013 "JPN" "010410"         0 8.960981  21.80353 43.48468 0  .6931472 0 0 .003891 0 0
    end
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str32 Destination int year str9 Origin str6 HS1992 float(ln_trade ln_dist ln_pop ln_gdp ln_tariff ln_Tech ln_NonTech) byte contig float(comrelig comlang_off) byte rta
    "USA" 1997 "JPN" "010111"  5.185266 9.293946  24.26073 45.06353         0  .6931472 0 0 .005724 0 0
    "USA" 1998 "JPN" "010111"  6.371641 9.293946 24.274914 45.01833         0 1.0986123 0 0 .005724 0 0
    "USA" 1999 "JPN" "010111"  5.714126 9.293946 24.288294 45.20358         0 1.3862944 0 0 .005724 0 0
    "USA" 2000 "JPN" "010111"  5.145522 9.293946 24.301157 45.33138         0  1.609438 0 0 .005724 0 0
    "USA" 2001 "JPN" "010111"  6.384272 9.293946  24.31325 45.23492         0 1.7917595 0 0 .005724 0 0
    "USA" 2002 "JPN" "010111" 9.1200285 9.293946 24.324854 45.22387         0   1.94591 0 0 .005724 0 0
    "USA" 2003 "JPN" "010111"  4.648258 9.293946  24.33559 45.34911         0   1.94591 0 0 .005724 0 0
    "USA" 2004 "JPN" "010111"  4.512375 9.293946  24.34518  45.4922         0   1.94591 0 0 .005724 0 0
    "USA" 2005 "JPN" "010111"  6.118254 9.293946  24.35449 45.53859         0 2.0794415 0 0 .005724 0 0
    "USA" 2006 "JPN" "010111"  6.652258 9.293946    24.364 45.54697         0 2.0794415 0 0 .005724 0 0
    "USA" 2007 "JPN" "010111" 8.2751255 9.293946 24.373627 45.59077         0 2.1972246 0 0 .005724 0 0
    "USA" 2008 "JPN" "010111"  5.228174 9.293946  24.38256 45.71445         0 2.3025851 0 0 .005724 0 0
    "USA" 2009 "JPN" "010111"         0 9.293946 24.390184  45.7315         0 2.3025851 0 0 .005724 0 0
    "USA" 2010 "JPN" "010111"  6.244064 9.293946 24.397635 45.85611         0 2.3025851 0 0 .005724 0 0
    "USA" 2011 "JPN" "010111"         0 9.293946 24.407776 45.96443         0  2.397895 0 0 .005724 0 0
    "USA" 2012 "JPN" "010111"         0 9.293946   24.4131 46.01341         0  2.484907 0 0 .005724 0 0
    "USA" 2013 "JPN" "010111"  5.360221 9.293946  24.41851 45.85923 1.4816046  2.564949 0 0 .005724 0 0
    "USA" 2014 "JPN" "010111"  5.959599 9.293946  24.42569 45.88132         0 2.6390574 0 0 .005724 0 0
    "USA" 2015 "JPN" "010111"  7.603399 9.293946 24.431927 45.81669  1.710188   2.70805 0 0 .005724 0 0
    "USA" 2016 "JPN" "010111"  5.111403 9.293946   24.4377 45.96527         0   2.70805 0 0 .005724 0 0
    "USA" 2017 "JPN" "010111"  3.172036 9.293946  24.44221 46.01466         0   2.70805 0 0 .005724 0 0
    "USA" 2018 "JPN" "010111"  5.823543 9.293946  24.44545 46.08919  1.710188   2.70805 0 0 .005724 0 0
    "USA" 2019 "JPN" "010111" 4.6238055 9.293946  24.44791 46.15023 2.0541236   2.70805 0 0 .005724 0 0
    "USA" 2020 "JPN" "010111"  5.266373 9.293946  24.44802 46.10974  1.710188   2.70805 0 0 .005724 0 0
    "USA" 2021 "JPN" "010111"         0 9.293946 24.454077 46.19318 2.0541236  2.772589 0 0 .005724 0 0
    "USA" 1997 "JPN" "010119"  6.945908 9.293946  24.26073 45.06353         0  .6931472 0 0 .005724 0 0
    "USA" 1998 "JPN" "010119"  7.681594 9.293946 24.274914 45.01833         0 1.0986123 0 0 .005724 0 0
    "USA" 1999 "JPN" "010119"  8.142611 9.293946 24.288294 45.20358         0 1.3862944 0 0 .005724 0 0
    "USA" 2000 "JPN" "010119"  6.657622 9.293946 24.301157 45.33138         0  1.609438 0 0 .005724 0 0
    "USA" 2001 "JPN" "010119"  9.154942 9.293946  24.31325 45.23492         0 1.7917595 0 0 .005724 0 0
    "USA" 2002 "JPN" "010119"  7.396735 9.293946 24.324854 45.22387 1.7917595   1.94591 0 0 .005724 0 0
    "USA" 2003 "JPN" "010119"  6.213433 9.293946  24.33559 45.34911 1.7934247   1.94591 0 0 .005724 0 0
    "USA" 2004 "JPN" "010119"  7.163478 9.293946  24.34518  45.4922 1.7561322   1.94591 0 0 .005724 0 0
    "USA" 2005 "JPN" "010119"   5.91841 9.293946  24.35449 45.53859  1.763017 2.0794415 0 0 .005724 0 0
    "USA" 2006 "JPN" "010119"  7.327434 9.293946    24.364 45.54697 1.7681496 2.0794415 0 0 .005724 0 0
    "USA" 2007 "JPN" "010119"  8.746555 9.293946 24.373627 45.59077  1.733424 2.1972246 0 0 .005724 0 0
    "USA" 2008 "JPN" "010119"  8.493533 9.293946  24.38256 45.71445  1.733424 2.3025851 0 0 .005724 0 0
    "USA" 2009 "JPN" "010119"  4.916237 9.293946 24.390184  45.7315 1.7833912 2.3025851 0 0 .005724 0 0
    "USA" 2010 "JPN" "010119"  7.391669 9.293946 24.397635 45.85611 1.7457155 2.3025851 0 0 .005724 0 0
    "USA" 2011 "JPN" "010119"  6.073123 9.293946 24.407776 45.96443 1.8099267  2.397895 0 0 .005724 0 0
    "USA" 2012 "JPN" "010119"  5.782307 9.293946   24.4131 46.01341         0  2.484907 0 0 .005724 0 0
    "USA" 2013 "JPN" "010119"  5.452891 9.293946  24.41851 45.85923         0  2.564949 0 0 .005724 0 0
    "USA" 2014 "JPN" "010119"  6.154829 9.293946  24.42569 45.88132         0 2.6390574 0 0 .005724 0 0
    "USA" 2015 "JPN" "010119"   7.92116 9.293946 24.431927 45.81669         0   2.70805 0 0 .005724 0 0
    "USA" 2016 "JPN" "010119"  6.218905 9.293946   24.4377 45.96527         0   2.70805 0 0 .005724 0 0
    "USA" 2017 "JPN" "010119"  5.951424 9.293946  24.44221 46.01466         0   2.70805 0 0 .005724 0 0
    "USA" 2018 "JPN" "010119"         0 9.293946  24.44545 46.08919  1.178655   2.70805 0 0 .005724 0 0
    "USA" 2019 "JPN" "010119"  7.283604 9.293946  24.44791 46.15023         0   2.70805 0 0 .005724 0 0
    "USA" 2020 "JPN" "010119"  6.128688 9.293946  24.44802 46.10974         0   2.70805 0 0 .005724 0 0
    "USA" 2021 "JPN" "010119"   6.21424 9.293946 24.454077 46.19318         0  2.772589 0 0 .005724 0 0
    "USA" 1997 "JPN" "010120"         0 9.293946  24.26073 45.06353 .22314355  .6931472 0 0 .005724 0 0
    "USA" 1998 "JPN" "010120"         0 9.293946 24.274914 45.01833 1.5993876 1.0986123 0 0 .005724 0 0
    "USA" 1999 "JPN" "010120"         0 9.293946 24.288294 45.20358         0 1.3862944 0 0 .005724 0 0
    "USA" 2000 "JPN" "010120"         0 9.293946 24.301157 45.33138  .8796268  1.609438 0 0 .005724 0 0
    "USA" 2001 "JPN" "010120"         0 9.293946  24.31325 45.23492   .662688 1.7917595 0 0 .005724 0 0
    "USA" 2002 "JPN" "010120"         . 9.293946 24.324854 45.22387         .   1.94591 0 0 .005724 0 0
    "USA" 2005 "JPN" "010120"         . 9.293946  24.35449 45.53859         . 2.0794415 0 0 .005724 0 0
    "USA" 2007 "JPN" "010120"         . 9.293946 24.373627 45.59077         . 2.1972246 0 0 .005724 0 0
    "USA" 2008 "JPN" "010120"         . 9.293946  24.38256 45.71445         . 2.3025851 0 0 .005724 0 0
    "USA" 2011 "JPN" "010120"         . 9.293946 24.407776 45.96443         .  2.397895 0 0 .005724 0 0
    "USA" 2012 "JPN" "010120"         . 9.293946   24.4131 46.01341         .  2.484907 0 0 .005724 0 0
    "USA" 2013 "JPN" "010120"         . 9.293946  24.41851 45.85923         .  2.564949 0 0 .005724 0 0
    "USA" 2014 "JPN" "010120"  4.337866 9.293946  24.42569 45.88132         . 2.6390574 0 0 .005724 0 0
    "USA" 2015 "JPN" "010120"         . 9.293946 24.431927 45.81669         .   2.70805 0 0 .005724 0 0
    "USA" 2021 "JPN" "010120"         . 9.293946 24.454077 46.19318         .  2.772589 0 0 .005724 0 0
    "USA" 1997 "JPN" "010210"  8.515325 9.293946  24.26073 45.06353         0  .6931472 0 0 .005724 0 0
    "USA" 1998 "JPN" "010210"  6.059198 9.293946 24.274914 45.01833         0  .6931472 0 0 .005724 0 0
    "USA" 1999 "JPN" "010210"         0 9.293946 24.288294 45.20358         0 1.0986123 0 0 .005724 0 0
    "USA" 2000 "JPN" "010210"         0 9.293946 24.301157 45.33138         0 1.3862944 0 0 .005724 0 0
    "USA" 2001 "JPN" "010210"         0 9.293946  24.31325 45.23492         0  1.609438 0 0 .005724 0 0
    "USA" 2002 "JPN" "010210"         0 9.293946 24.324854 45.22387         0 1.7917595 0 0 .005724 0 0
    "USA" 2003 "JPN" "010210"         0 9.293946  24.33559 45.34911         0   1.94591 0 0 .005724 0 0
    "USA" 2004 "JPN" "010210"         0 9.293946  24.34518  45.4922         0 2.0794415 0 0 .005724 0 0
    "USA" 2005 "JPN" "010210"         0 9.293946  24.35449 45.53859         0 2.1972246 0 0 .005724 0 0
    "USA" 2007 "JPN" "010210"         0 9.293946 24.373627 45.59077         0 2.1972246 0 0 .005724 0 0
    "USA" 2008 "JPN" "010210"         0 9.293946  24.38256 45.71445         0 2.3025851 0 0 .005724 0 0
    "USA" 2009 "JPN" "010210"         0 9.293946 24.390184  45.7315         0 2.3025851 0 0 .005724 0 0
    "USA" 2010 "JPN" "010210"         0 9.293946 24.397635 45.85611         0  2.397895 0 0 .005724 0 0
    "USA" 2011 "JPN" "010210"         0 9.293946 24.407776 45.96443         0  2.484907 0 0 .005724 0 0
    "USA" 2012 "JPN" "010210"         0 9.293946   24.4131 46.01341         0  2.564949 0 0 .005724 0 0
    "USA" 2013 "JPN" "010210"         0 9.293946  24.41851 45.85923         0 2.6390574 0 0 .005724 0 0
    "USA" 2014 "JPN" "010210"         0 9.293946  24.42569 45.88132         0   2.70805 0 0 .005724 0 0
    "USA" 2015 "JPN" "010210"         0 9.293946 24.431927 45.81669         0  2.772589 0 0 .005724 0 0
    "USA" 2016 "JPN" "010210"         0 9.293946   24.4377 45.96527         0  2.772589 0 0 .005724 0 0
    "USA" 2017 "JPN" "010210"         0 9.293946  24.44221 46.01466         0  2.772589 0 0 .005724 0 0
    "USA" 2018 "JPN" "010210"         0 9.293946  24.44545 46.08919         0  2.772589 0 0 .005724 0 0
    "USA" 2019 "JPN" "010210"         0 9.293946  24.44791 46.15023         0  2.772589 0 0 .005724 0 0
    "USA" 2020 "JPN" "010210"         0 9.293946  24.44802 46.10974         0  2.772589 0 0 .005724 0 0
    "USA" 2021 "JPN" "010210"         0 9.293946 24.454077 46.19318         0  2.833213 0 0 .005724 0 0
    "USA" 1997 "JPN" "010290"  8.468353 9.293946  24.26073 45.06353  .6259384  .6931472 0 0 .005724 0 0
    "USA" 1998 "JPN" "010290"  6.450894 9.293946 24.274914 45.01833         0  .6931472 0 0 .005724 0 0
    "USA" 1999 "JPN" "010290"         0 9.293946 24.288294 45.20358         0 1.0986123 0 0 .005724 0 0
    "USA" 2000 "JPN" "010290"         0 9.293946 24.301157 45.33138         0 1.3862944 0 0 .005724 0 0
    "USA" 2001 "JPN" "010290"         0 9.293946  24.31325 45.23492         0  1.609438 0 0 .005724 0 0
    "USA" 2002 "JPN" "010290"         0 9.293946 24.324854 45.22387         0 1.7917595 0 0 .005724 0 0
    "USA" 2003 "JPN" "010290"         0 9.293946  24.33559 45.34911         0   1.94591 0 0 .005724 0 0
    "USA" 2004 "JPN" "010290"         0 9.293946  24.34518  45.4922         0 2.0794415 0 0 .005724 0 0
    "USA" 2005 "JPN" "010290"         0 9.293946  24.35449 45.53859         0 2.1972246 0 0 .005724 0 0
    "USA" 2006 "JPN" "010290"         0 9.293946    24.364 45.54697         0 2.1972246 0 0 .005724 0 0
    "USA" 2007 "JPN" "010290"         0 9.293946 24.373627 45.59077         0 2.1972246 0 0 .005724 0 0
    end

  • #2
    The trick is to -xtset- the data to the country pair and the year. Your code does not do that. What you need is:

    Code:
    egen country_pair = group(Origin Destination)
    xtset country_pair
    xtreg ln_trade ln_dist ln_pop ln_gdp ln_tariff ln_Tech ln_NonTech rta comlang_off comrelig contig i.year, fe robust
    Notice that I do not specify a time variable in the -xtset- command. Your data is not country-pair year panel data: you do have multiple observations for every country-pair-year combination in your example. They seem to differ by some variable called HS1992 (whatever that is) and also differ on ln_trade, ln_tariff, and ln_Tech. Perhaps HS1992 indicates different industrial sectors, or product categories or something like that? So you cannot include a time variable with -xtset-. But you also have no need of one for the analysis you are proposing. You only need to include a time variable in -xtset- if you are going to use time series operators like lags and leads, or estimate autoregressive structure.

    Your ln_dist variable is still not going to drop, because, in your example data, while most of your observations give the AUS JPN distance as 8.960981, there are two that give it as 9.006509. Clearly there is a data error here. At least one of these values must be wrong. There may be other data errors like this in your full data. So you need to go back over the data management that created this data set and figure out where things went wrong, leading to having inconsistent values of distance for the same country pair. Fix that error, and any others you uncover in the process, before attempting to proceed. There is no point analyzing manifestly wrong data.

    I don't understand why you expect the GDP variable to drop. Doesn't GDP change from year to year?

    Comment


    • #3
      Christine:
      1) your first code is not a fixed effect regression; hence, no omission of time-invariant variables has to be expected;
      2) your supervisor is right. Unless your data were already -xtset- Stata should have warned you about this omission with no clearance to move forward to -xtreg-;
      3) the usual workaround to the "repeated time values within panel". error is to -xtset- your dataset with the -panelid- only. However, you should be informed that this fix comes at the cost of making time-series operators, such as lags and leads, unavailable (but you can still add -i.timevar- as a predictor).
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X