Announcement

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

  • Panel Data Techniques

    Hello,
    I'm running a fixed effect model (after proven by Hausman Test) and I'm not sure if the code is right. I'm using "xi: reg" and ",rob" and I saw in a forum here that "xtreg" and ",fe" should give me the same coefficients but it's not happening.

    These are the codes:
    xi: reg reconsumption lngdppctogether gdpgrowth govfinalconsumpexpendgdp gdpperunitofenergy trade energyimports energyuse oilprice lnpoptotal popdensity urbanpop accesstoelectricity lnrailways lnairtransport i.country, rob

    xtreg reconsumption lngdppctogether gdpgrowth govfinalconsumpexpendgdp gdpperunitofenergy trade energyimports energyuse oilprice lnpoptotal popdensity urbanpop accesstoelectricity lnrailways lnairtransport i.country, fe

    I'm sorry if it is a silly question. I'm new at Stata.
    Thanks!

  • #2
    Somewhere before -xtreg- you should have

    xtset panelvar timevar

    what are the panelvar and the timevar that you have set?

    Comment


    • #3
      Joyce:
      welcome to this forum.
      Some comments about your query:
      - it's rare (although possible) that (pooled) -regress- outperforms -xtreg- with panel data. This can happen if, after running -xtreg,fe- with default standard errors (SEs), the F-test appearing below the outcome table lacks statistical significance; if that were the case, switch to pooled OLS;
      - if, as warmly recommended, you use -fvvarlist- for creating categorical variables and interactions -xi:- is redundant;
      - the -robust- and -cluster- options for SEs do the same job under -xttreg-, but act differently under -regress-. In your -regress- code, you have taken heteroskedasticity into account, but not autocorrelation (that requires -cluster-);
      - last but not least, as per FAQ please post also what Stata gave you back, so that interested listers can see what's the matter with your "weird" results. Please use CODE delimiters to share what you typed and what Stata gave you back. If you're not familiar with code tags, take a comprehensive look at the FAQ, that highlight relevant posting related topics in addition to CODE delimiters. Thanks.

      PS: crossed in the cyberspace with Joro's helpful advice.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        Joro:

        Thank you!

        I wrote
        Code:
        xtset country
        Code:
        xtsetyear

        Comment


        • #5
          Carlo, Thank you!

          I need to admit that I got confused with your answer.

          -After runnig - xtreg,fe-, the F test result was Prob > F = 0.0000. I think that is good, right?
          -How do I account for autocorrelation and heteroskedasticity at the same time? Using the code
          Code:
          cluster(countey)
          ?
          -I'm reading the FAQ now, thanks!

          Comment


          • #6
            I think Carlo is answering you at more advanced level relative to the errors that you are currently committing.

            It you had properly xtset your data by

            xtset country year

            and then you tried

            xtreg y x i.country, fe

            Stata would have reported to you that all the i.country dummies are being dropped.

            I think it is best at this point if you just do:

            xtset country year

            xtreg y x, fe cluster(country)

            Note that you must not include the i.country term.

            Comment


            • #7
              xtset country year

              xtreg reconsumption lngdppctogether gdpgrowth govfinalconsumpexpendgdp gdpperunitofenergy trade energyimports energyuse oilprice lnpoptotal popdensity urbanpop accesstoelectricity lnrailways lnairtransport i.year, fe robust cluster(country)


              Note the difference between this, and your code, the -xtset- is different, and then instead of including i.country (which you cannot include) you include i.year.

              Comment


              • #8
                Joro,
                In all of my regressions I have being using
                Code:
                 xi: reg reconsumption lngdppctogether gdpgrowth govfinalconsumpexpendgdp gdpperunitofenergy trade energyimports energyuse oilprice lnpoptotal popdensity  urbanpop accesstoelectricity lnrailways lnairtransport  i.country, rob
                When I use
                Code:
                xtreg reconsumption lngdppctogether gdpgrowth govfinalconsumpexpendgdp gdpperunitofenergy trade energyimports energyuse oilprice lnpoptotal popdensity  urbanpop accesstoelectricity lnrailways lnairtransport  i.country, fe
                Only some of the countries are omitted.

                If I want to see the country specific effect for the country, why not use i.country?

                I tried the code
                Code:
                xtreg y x, fe cluster(country)
                and stata gave me that "panels are not nested within clusters r(498)"

                Comment


                • #9
                  The -xtreg, fe- applies the within transformation to the data, and after that everything that is constant within the panel variable (country in your case) drops out/becomes collinear with the constant.

                  The within transformation is equivalent to the dummy variable regression, that is including i.country. Therefore

                  reg y x i.country

                  is equivalent to

                  xtset country year

                  xtreg y x, fe

                  and in the second you do not need to include, and in fact cannot include the i.country terms.

                  The only reason that I can think of Stata not dropping all country dummies, but only some is that you might have unbalanced panel.

                  As for the rest that you say, I do not see your data, so I do not know why "panels are not nested within clusters r(498)", your panels are country, so I cannot guess from where this error message comes from.

                  Comment


                  • #10
                    Joyce,

                    I would try tabulate country to see if there is anything funny with that variable (for example, some observations "change" countries over time, or one country has multiple obs for the same year).

                    See this Statalist topic, "panels are not nested within clusters" and this one (on StackExchange) Stata error: “panels are not nested within clusters”

                    Comment


                    • #11
                      Joyce:
                      if, after runnig - xtreg,fe-, the F test result was Prob > F = 0.0000, pooled OLS is not the way to go and -xtreg,fe- should be considered.
                      Kind regards,
                      Carlo
                      (Stata 19.0)

                      Comment

                      Working...
                      X