Hi Statalist.

I am estimating a model with fixed effects and factor variables. I can estimate it using -areg-, -reg-, -xtreg- or -reghdfe-. With all the commands but -reghdfe- I get different results when I use the factor variables in the regression, compared to when I generate the variables beforehand and then I include them in the regression. These are differences in coefficients with the same estimation method. The differences in standard errors across methods should be expected.

Here's the code I am using:

Code:
gen i0 = 1.intent#0.defier#1.m0
gen i1 = l1.1.intent#l1.0.defier#1.m1
gen i2 = l2.1.intent#l2.0.defier#1.m2
gen i3 = l3.1.intent#l3.0.defier#1.m3


foreach method in areg reghdfe {

# delimit ;
    `method' ${outcome}

    1.intent#0.defier#1.m0
    l1.1.intent#l1.0.defier#1.m1
    l2.1.intent#l2.0.defier#1.m2
    l3.1.intent#l3.0.defier#1.m3

    c.running#0.defier#1.m0
    l1.c.running#l1.0.defier#1.m1
    l2.c.running#l2.0.defier#1.m2
    l3.c.running#l3.0.defier#1.m3

    0.defier#m0
    0.l1.defier#m1
    0.l2.defier#m2
    0.l3.defier#m3
    
    i.year
    
            
    wave0 l1wave0 l2wave0 l3wave0
    l(4/6).rdtreat
    l(4/6).rdtreat2    
    
                        
    if inrange(year,1996,2006)
    & insample                
    , cluster(cty) absorb(cty);
# delimit cr
est store `method'1



# delimit ;
    `method' ${outcome}

    i0
    i1
    i2
    i3

    c.running#0.defier#1.m0
    l1.c.running#l1.0.defier#1.m1
    l2.c.running#l2.0.defier#1.m2
    l3.c.running#l3.0.defier#1.m3

    0.defier#m0
    0.l1.defier#m1
    0.l2.defier#m2
    0.l3.defier#m3
    
    i.year
    
            
    wave0 l1wave0 l2wave0 l3wave0
    l(4/6).rdtreat
    l(4/6).rdtreat2    
    
                        
    if inrange(year,1996,2006)
    & insample                
    , cluster(cty) absorb(cty);
# delimit cr
est store `method'2
}
The code for -xtreg- is similar, I am using the fe option. Method 1 uses the factor variables in the regression, method 2 creates them beforehand. Here's a table with the results. As you can see, the areg1 and areg2 (xtreg1 and xtreg2) columns are different, but the reghdfe1 and reghdfe2 columns are the same.

Code:
. est tab areg* reghdfe* xtreg*, b(%9.3f)

--------------------------------------------------------------------------------------
    Variable |   areg1       areg2     reghdfe1    reghdfe2     xtreg1      xtreg2    
-------------+------------------------------------------------------------------------
      intent#|
   defier#m0 |
      1 0 1  |     0.052                   0.014                   0.052              
             |
    L.intent#|
 L.defier#m1 |
      1 0 1  |     0.164                   0.210                   0.164              
             |
   L2.intent#|
L2.defier#m2 |
      1 0 1  |    -0.489                  -0.566                  -0.489              
             |
   L3.intent#|
L3.defier#m3 |
      1 0 1  |    -0.445                  -0.382                  -0.445              
             |
   defier#m0#|
   c.running |
        0 1  |    -0.010      -0.010      -0.010      -0.010      -0.010      -0.010  
             |
 L.defier#m1#|
  cL.running |
        0 1  |     0.005       0.006       0.006       0.006       0.005       0.006  
             |
         L2. |
      defier#|
          m2#|
 cL2.running |
        0 1  |    -0.008      -0.010      -0.010      -0.010      -0.008      -0.010  
             |
         L3. |
      defier#|
          m3#|
 cL3.running |
        0 1  |     0.009       0.009       0.009       0.009       0.009       0.009  
             |
   defier#m0 |
        0 1  |     0.265       0.276       0.276       0.276       0.265       0.276  
             |
 L.defier#m1 |
        0 1  |    -0.255      -0.304      -0.304      -0.304      -0.255      -0.304  
             |
L2.defier#m2 |
        0 1  |     0.290       0.364       0.364       0.364       0.290       0.364  
             |
L3.defier#m3 |
        0 1  |    -0.178      -0.217      -0.217      -0.217      -0.178      -0.217  
             |
        year |
       1997  |    -0.653      -0.657      -0.657      -0.657      -0.653      -0.657  
       1998  |    -0.798      -0.801      -0.801      -0.801      -0.798      -0.801  
       1999  |    -1.030      -1.031      -1.031      -1.031      -1.030      -1.031  
       2000  |    -0.489      -0.491      -0.491      -0.491      -0.489      -0.491  
       2001  |     1.685       1.680       1.680       1.680       1.685       1.680  
       2002  |     2.961       2.957       2.957       2.957       2.961       2.957  
       2003  |     2.468       2.461       2.461       2.461       2.468       2.461  
       2004  |     1.608       1.602       1.602       1.602       1.608       1.602  
       2005  |     1.369       1.366       1.366       1.366       1.369       1.366  
       2006  |     0.954       0.947       0.947       0.947       0.954       0.947  
             |
       wave0 |     0.928       0.917       0.917       0.917       0.928       0.917  
     l1wave0 |     0.898       0.908       0.908       0.908       0.898       0.908  
     l2wave0 |     0.572       0.556       0.556       0.556       0.572       0.556  
     l3wave0 |     0.605       0.606       0.606       0.606       0.605       0.606  
             |
     rdtreat |
         L4. |    -0.828      -0.836      -0.836      -0.836      -0.828      -0.836  
         L5. |     0.063       0.054       0.054       0.054       0.063       0.054  
         L6. |    -1.002      -0.999      -0.999      -0.999      -1.002      -0.999  
             |
    rdtreat2 |
         L4. |    -0.200      -0.195      -0.195      -0.195      -0.200      -0.195  
         L5. |    -0.126      -0.126      -0.126      -0.126      -0.126      -0.126  
         L6. |    -0.364      -0.354      -0.354      -0.354      -0.364      -0.354  
             |
          i0 |                 0.014                   0.014                   0.014  
          i1 |                 0.210                   0.210                   0.210  
          i2 |                -0.566                  -0.566                  -0.566  
          i3 |                -0.382                  -0.382                  -0.382  
       _cons |     5.597       5.601                               5.597       5.601  
--------------------------------------------------------------------------------------
Thank you,