Dear all,
I am having some issues with getting different results for my coefficients of interest using different fixed effects estimation commands in Stata. I haven't been able to find anything on this searching the forum so I post here.
I know that the fixed effects coefficients will change between different commands because the parametrize them differently, but this is not supposed to affect other coefficients as far as I know. Currently I am working on data where students take several exams (between 2 and 5) in different subjects (82) across several years (5). Students are not necessarily tested in the same subjects or years. My variable of interest is measured at the subject-year level. When I estimate a model where I include subject, student, and year fixed effects I get the same results regardless of which of the three commands above. However, when I interact the fixed effects I get wild different results. For example if I include subject by year fixed effects I would expect the all models to return results where my variable of interest was omitted. This is not, however, the case. reghdfe reports quite precise zeros.
I cannot share my data, but I have been able to recreate the problem in constructed data with the same structure as my own. The code is included below. I have refrained from posting the results from running this code, but I believe it is easily found by just running it.
Thank you kindly for all suggestions, questions, or explanations.
I am having some issues with getting different results for my coefficients of interest using different fixed effects estimation commands in Stata. I haven't been able to find anything on this searching the forum so I post here.
I know that the fixed effects coefficients will change between different commands because the parametrize them differently, but this is not supposed to affect other coefficients as far as I know. Currently I am working on data where students take several exams (between 2 and 5) in different subjects (82) across several years (5). Students are not necessarily tested in the same subjects or years. My variable of interest is measured at the subject-year level. When I estimate a model where I include subject, student, and year fixed effects I get the same results regardless of which of the three commands above. However, when I interact the fixed effects I get wild different results. For example if I include subject by year fixed effects I would expect the all models to return results where my variable of interest was omitted. This is not, however, the case. reghdfe reports quite precise zeros.
I cannot share my data, but I have been able to recreate the problem in constructed data with the same structure as my own. The code is included below. I have refrained from posting the results from running this code, but I believe it is easily found by just running it.
Thank you kindly for all suggestions, questions, or explanations.
Code:
clear set obs 10000 gen studentid = int(_n/5)+1 gen double u = (100-1)*runiform() + 1 gen double subjectid = round(u) drop u sort studentid subjectid by studentid: drop if subjectid == subjectid[_n-1] gen double uu = (6-1)*runiform() + 1 gen double examscore = round(uu) drop uu gen uuu = (2012-2008)*runiform() + 2008 gen examyear = round(uuu) drop uuu sort subjectid examyear by subjectid examyear: gen double uuuu = (25-5)*runiform() + 5 if _n == 1 gen double x = round(uuuu) drop uuuu by subjectid examyear: replace x = x[_n-1] if x == . sort student by student: gen double uuuuu = (200-1)*runiform() + 1 if _n == 1 gen double school = round(uuuuu) by student: replace school = school[_n-1] if school == . areg examscore x i.examyear i.subjectid, absorb(studentid) xtset studentid xtreg examscore x i.examyear i.subjectid, fe reghdfe examscore x, absorb(studentid subjectid examyear) set matsize 4000 egen d_subject_year = group(subject examyear) areg examscore x i.d_subject_year i.examyear i.subjectid, absorb(studentid) cluster(school) xtset studentid xtreg examscore x i.d_subject_year i.examyear i.subjectid, fe cluster(school) reghdfe examscore x, absorb(studentid d_subject_year examyear subjectid) cluster(school)

Comment