Announcement

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

  • Time-varying country fixed effects

    Hi all,

    I'm new to Stata and I haven't been able to include time-varying country fixed effects (a dummy for each country-year pair). Also, I need to cluster errors at the Country_Year level. I have tried with the next piece of code


    encode Country, gen (Countries)
    egen CountryD = group (Countries)
    egen YearD = group (Year)
    egen Country_Year = group (CountryD YearD)
    xtset Countries Country_Year
    xtline Y
    xtline Y , overlay

    xtreg Y X1 X2 X3 X4 i.Country_Year, fe vce(cluster Country_Year)


    The error message that I get after running it is "panels are not nested within clusters".
    Could you please tell me how to fix this problem? I'd really appreciate it.

  • #2
    I think what you actually want is:

    Code:
    egen Country_Year = group (Country Year)
    xtset Country_Year 
    xtline Y
    xtline Y , overlay
    xtreg Y X1 X2 X3 X4, fe vce(cluster Country_Year)

    Comment


    • #3
      Dear Clyde Schechter thank you very much for your answer. However, when I run it in this new way I get the error message "too few variables specified" under "xtline Y".

      Basically I am doing a difference in difference analysis. My treatment group is given by a group of countries which passed legal reforms (in different points of time). So, I want to include time-varying country fixed effects (a dummy for each country-year pair) to control for unobservable differences. Thus, it is possible to exploit only the within country-year variation and control for all time-varying country-specific variables correlated to the passage of legal reforms. The aim of this is to avoid that unobserved omitted country-specific variables drive the results.

      Could you please tell me which would be the best way to code this in Stata. Thank you very much!!

      Comment


      • #4
        Sorry, it should be
        Code:
        xtline Y year
        The use of -xtline- is a bit complicated. When you have -xtset panel_var time_var-, you can have a command -xtline X-, which will cause Stata to plot a line graph of X vs the time_var for each panel. But in this case, we have only -xtset panel_var- (panel, in this case being the country-year pair). So there is no time var in the -xtset- command for Stata to use on the horizontal axis. So it has to be specified in the command, hence, -xtline Y year-.

        Comment


        • #5
          Dear Clyde Schechter thank you very much again for your answer. Your explanation is very useful for improving my understanding.

          Unfortunately, I have run the regression with the suggested change in xtline, but now I get the error message "too few variables specified" under "xtline Y, overlay".
          I tried to fix it by adding year, but the option "overlay" doesn't allow me to do it. I'd really appreciate if you can provide me more insight about this. Thank you very much.

          Comment


          • #6
            I had intended that you also add year to the -xtline Y, overlay- command. I'm sorry I didn't make that clearer.

            Oh, sorry, I see you tried that and it gave you an error message. Then do it this way:

            Code:
            xtline Y, i(Country) t(year) overlay

            Comment


            • #7
              Thank you very much Clyde! Your answers are very useful.

              Comment

              Working...
              X