Announcement

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

  • Time and importer/exporter fixed effect

    Dear Statalist Forum,
    I need your help for my working paper. I have learn in this forum many things about fixed effet but I begin in stata so....I ask you a little help.

    I work on exportations between country (i), country(j), time (year) and products (hs). Every flow is specified by this 4 components. Time value is 2008,2010,2012,2014,2016 and 2018. Every country have number iso, code iso and namecountry (respectively named i isoi countryi and j isoj countryj). i=94 country and j=94 country.
    I would make a regression of my dependant variable (q) and my explicative variable (gradianport). Gradianport is a score of port infrastructure between country i and country j.

    I would like to create exporter (for country i) time effect and importer (for country j) time effect.
    Click image for larger version

Name:	Capture d’écran (262).png
Views:	1
Size:	41.9 KB
ID:	1547318



    I have test a stata command xtset to create time fixed effect:

    xtset i j hs year , delta(2) ==> error 103: too many variables specified

    xtset i year, delta(2) ==> error 451; repeated time values within panel

    I don't know how specified my import(j) and export(i) variable.

    After this step, I need to use: xtreg q gradiantport i.year i.i i.j, fe , no?

    Thank you for your help,




    Florian Palmito


  • #2
    It's not entirely clear to me what you want to do.

    Do you want to have separate fixed effects for the import and exporter, as well as a time fixed effect in your model? Or do you want a fixed effect for the importer-exporter pair, in addition to a time fixed effect?

    For the first:

    Code:
    xtset i
    xtreg q gradianport i.j i.year, fe
    For the second:
    Code:
    egen i_e_pair = group(i j)
    xtset i_e_pair
    xtreg q gradianport i.year, fe
    The -xtset- command only sets one variable as a panel designator--as you have discovered, attempting to set more will fail. If you need multiple separate fixed effects in your model, you need to introduce one by -xtset- and the others as covariates in the model.

    It is not necessary to specify a time variable in -xtset-. If you do, it enables you to use lag and lead operators and run models with autoregressive structure. But if you are not using those things, there is nothing gained by mentioning a time variable in your -xtset- command (except a verification that your panel and time variables jointly identify unique observations in the data --but you can do that with -isid-.)


    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Added: Another, possibly simpler, approach to models with multiple fixed effects is to use Segio Correa's -reghdfe-, available from SSC.
    Last edited by Clyde Schechter; 16 Apr 2020, 12:32.

    Comment


    • #3
      Dear Clyde,

      Thank you a lot for your help. I would like fixed effect ij and time fixed effect. I think you have answered this question.

      Florian Palmito

      Comment


      • #4
        Clyde Schechter your #2 replies my query a bit but what if i want three fixed effects in my OLS model, one for importer-time fixed effect, other exporter-time fixed effect and at last country pair invariant fixed effect. how to include these three FEs in the OLS model. thank you

        Comment


        • #5
          You are going to have an enormous number of fixed effects cluttering up your output with useless coefficients. I would not do this with -regress-. I would use -reghdfe-, by Sergio Correa, available from SSC.
          Code:
          reghdfe dep_var ind_vars, absorb(exporter#time importer#time exporter#importer)

          Comment


          • #6
            thank you Clyde Schechter for your prompt reply. i agree with your #5 reply. actually my preferred command for the said query is ppmlhdfe but i need OLS with 3 FEs for my research paper as a benchmark specification against whom i will compare my preferred specification. so kindly provide code for OLS with 3FEs irrespective of the number of co-efficients.
            thank you once again.

            Comment


            • #7
              OK
              Code:
              regress dep_var ind_vars i.exporter#i.time i.importer#i.time i.exporter#i.importer

              Comment


              • #8
                thank you Clyde Schechter . #7 code helped

                Comment


                • #9
                  Originally posted by Clyde Schechter View Post
                  You are going to have an enormous number of fixed effects cluttering up your output with useless coefficients. I would not do this with -regress-. I would use -reghdfe-, by Sergio Correa, available from SSC.
                  Code:
                  reghdfe dep_var ind_vars, absorb(exporter#time importer#time exporter#importer)
                  Dear Clyde Schechter. I want to apply #5, but I have unbalanced panel data. Is there any problems/issues if the code #5 is applied for unbalanced panel data?

                  Thank you in advance.

                  Comment


                  • #10
                    No, unbalanced data is not a problem. Whatever limitations unbalanced data may impose, they would apply equally strongly with -xtreg, fe- or -reghdfe-.

                    Comment


                    • #11
                      Originally posted by Clyde Schechter View Post
                      No, unbalanced data is not a problem. Whatever limitations unbalanced data may impose, they would apply equally strongly with -xtreg, fe- or -reghdfe-.
                      Dear Clyde Schechter.
                      Thank you for your help.
                      I have one more question.
                      My data have some missing values in some years. I don't want to delete the countries having missing values.
                      Is there any special options in the syntax of the command fe- or -reghdfe- to apply for missing value?

                      Comment


                      • #12
                        With -xtreg- and -reghdfe-, as with all Stata estimation commands, any observation that contains a missing value for any variable in the command is omitted from the estimation sample. This is done automatically and you don't have to do anything to make that happen.

                        Missing data is, of course, a problem, because it can result in biased estimates if the missing values are not missing completely at random. There are no good solutions to this problem. One seeks to find the least bad solution under the particular circumstances. Under the strong, and inherently unverifiable, assumption that the missing values arose from a missing at random process, the use of multiple imputation can reduce this bias. And -xtreg- is supported by Stata's -mi estimate- command. -reghdfe-, as far as I know, is not, although I believe (but am not certain) that it would produce useful results if used with -mi estimate-'s -cmdok- option.

                        The general topic of missing data is fairly complicated. For a readable introduction, with examples in Stata, I recommend https://statisticalhorizons.com/wp-c...aterials-1.pdf.

                        Comment

                        Working...
                        X