I've got a question about the behavior of ereturn repost using the resize option. I also have a subtler question about the negative effects of what I'm asking my program to do (which I'm aware is a little bonkers), but if that question goes unanswered, it's okay.
I have several tests that I have to run with one or two thousand dummied fixed effects, usually using the factor variable convenience i.dumvar. The result, of course, is that the interactive terminal window fills up with all of the coefficient estimates on the dummy variables. I want to be clear up front that I'm not necessarily opposed to this behavior, I always like to scan the coefficients on the fixed effects so that I'm aware of the behavior, but for the purposes of reporting I'm never going to use them. The problem is that outputting the results of these tests to a table takes forever. This is obviously true when writing tables by hand and having to scan the code, but it's also true that programs like estout take forever because they have to manually process all of the thousands of rows in each column that they ultimately end up dropping.
In order to deal with this, I wrote the following program. It takes a wildcard input like say "*.dumvar1 *.dumvar2" and then creates a new coefficient and covariance matrix which excludes the coefficients matching the wildcard. It then reposts to e() using the resize option. I'm aware that econometrically this is deeply suspect, but the use case is just for reporting so that estimates store only needs to hold the variables I ultimately intend to report.
Here's my question
I have several tests that I have to run with one or two thousand dummied fixed effects, usually using the factor variable convenience i.dumvar. The result, of course, is that the interactive terminal window fills up with all of the coefficient estimates on the dummy variables. I want to be clear up front that I'm not necessarily opposed to this behavior, I always like to scan the coefficients on the fixed effects so that I'm aware of the behavior, but for the purposes of reporting I'm never going to use them. The problem is that outputting the results of these tests to a table takes forever. This is obviously true when writing tables by hand and having to scan the code, but it's also true that programs like estout take forever because they have to manually process all of the thousands of rows in each column that they ultimately end up dropping.
In order to deal with this, I wrote the following program. It takes a wildcard input like say "*.dumvar1 *.dumvar2" and then creates a new coefficient and covariance matrix which excludes the coefficients matching the wildcard. It then reposts to e() using the resize option. I'm aware that econometrically this is deeply suspect, but the use case is just for reporting so that estimates store only needs to hold the variables I ultimately intend to report.
Here's my question
- This works after most basic estimation commands, but doesn't work after regress apparently because of the way regress posts to e(). Why is this, and is there any way to fix it?
- Is there anything bonkers about what I'm doing that would affect reporting in ways that I do not yet realize. Again, I'm aware that an ocean of problems probably exist using the results for postestimation, but is there a problem for the reporting use case.
Code:
program define ProgName, eclass syntax anything(name=eqdrop) tempname eb eV b V Vcol element matrix `eb' = e(b) matrix `eV' = e(V) local x = 0 local varpos = "" local varnames: colnames `eb' foreach var in `varnames' { local x = `x' + 1 local matched = 0 foreach m in `eqdrop' { if strmatch("`var'", "`m'") { local matched = 1 } } if `matched' == 0 { local varpos "`varpos' `x'" } } foreach colnum of numlist `varpos' { foreach rownum of numlist `varpos' { matrix `element' = `eV'[`colnum'..`colnum',`rownum'..`rownum'] capture confirm matrix `Vcol'_`colnum' if _rc { matrix `Vcol'_`colnum' = `element' } else { matrix `Vcol'_`colnum' = `Vcol'_`colnum' \ `element' } } matrix `element' = `eb'[1,`colnum'..`colnum'] capture confirm matrix `b' if _rc { matrix `b' = `element' matrix `V' = `Vcol'_`colnum' } else { matrix `b' = `b',`element' matrix `V' = `V',`Vcol'_`colnum' } } ereturn repost b=`b' V=`V', resize estimates replay end