Dear Stata experts,

I recently learned how to change the degrees of freedom in the regress command using the dof() option (Thanks Trent Mize). This can be very handy when estimating a fixed effects model using the regress command with manually demeaned variables (example from Trent at the end of this post).

I would like a way to change the df like this when estimating an OLS regression using sem. The dof() option is not available, and the two other strategies I tried have not worked yet:


Strategy 1
I can change the df after regress like this:

mata: st_numscalar("e(df_r)", 21761)
Unfortunately, this approach does not seem to update the t statistics or confidence intervals. I have not tried that approach yet with sem.

Strategy 2
It also looks like the df can also be changed with the ereturn repost command (see Stata Forum post), but I am not sure how to do that without deleting the b and V matrices.


Does anyone know how to replicate the effect of the dof() option in a way that will work with sem?


Thanks,

Jeremy


Code:
webuse union, clear

**************************************************************************    
// #0 - Data Management
**************************************************************************    

drop if missing(union, age, grade, not_smsa, south, year)

*Calculate person-specific means and demean the variables (subtract the person
*specific mean from each so the new value represents the deviation from 
*the subject-specific average)
local ivs "union age grade not_smsa south year"
foreach v in `ivs' {
    egen     `v'M = mean(`v'), by(idcode)
    gen     `v'D = `v' - `v'M
    }
    
**************************************************************************    
// #1 - Show normal FE model with xtreg
**************************************************************************    
xtset         idcode

xtreg         grade age union i.not_smsa south c.year, fe
est             store fixed


**************************************************************************    
// #2 - Use all demenaed vars (DV and IVs)
**************************************************************************    
*Fixed effects models using all demeaned vars    
*Force df to be correct with dof() option (from FE models estimated earlier)
reg         gradeD ageD unionD not_smsaD southD yearD,   dof(21761)
est store    demean    

********************************
*Compare the estimates
********************************
esttab fixed demean, nobase noconstant