Announcement

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

  • TWFE: Different results between Stata and R

    Hi,

    We are running two-way fixed effects on R and Stata using the same data, and they are giving different results. The coefficients are not only different but the sign is opposite as well.

    In R, the command we're using is:
    Code:
    feols(log(income) ~ treat + var1 + var2 + var3 | state + year, data=df)
    In Stata, the command we're using is:
    Code:
    twfe log_income treat var1 var2 var3, ids(state year) cluster(state)
    The data we're using is the same. Are the two lines of code equivalent in the respective programs or are they different?

    Thank you!

  • #2
    Samyam, even within Stata, -twfe- may generate different results from more widely used commands, like -xtreg-. I just tried an example, and not sure what happened. You may try -xtreg- and see whether the results are identical to those from R.

    Code:
    xtreg log_incom treat var1 var2 var3 i.year, fe vce(cluster state)

    Comment


    • #3
      Hi Fei Wang, thanks for the comment!

      My dataset is not panel, so I instead used the following regression code for my repeated cross-sectional data:
      Code:
      reg log_income treat var1 var2 var3 i.year i.state, vce(cluster state)
      As you said, the coefficients are different from the previous two approaches.

      Having said that, between -twfe- (Stata) and -feols- (R), the fact that the coefficient sign completely flips is very troublesome to me, from the policy evaluation standpoint, unless something is wrong with one of my codes.

      Comment


      • #4
        Samyam, I think at least you may try several equivalent codes within Stata to see whether the coefficients are identical (Standard errors may differ.).

        Code:
        // Estimation one
        reg log_income treat var1 var2 var3 i.year i.state, vce(cluster state)
        
        // Estimation two
        xtset state
        xtreg log_income treat var1 var2 var3 i.year, fe vce(cluster state)
        
        // Estimation three: need to install -reghdfe-
        reghdfe log_income treat var1 var2 var3, absorb(state year) vce(cluster state)

        Comment

        Working...
        X