I have already asked a question about storing coefficients and standard errors of several regressions in a single dataset.
Let me just reiterate the objective of my initial question:
I would like to run several regressions and store their results in a DTA file that I could later use for analysis. My constraints are:
- I cannot install modules (I am writing code for other people and not sure what modules they have installed)
- Some of the regressors are factor variables.
- Each regression differ only by the dependent variable, so I would like to store that in the final dataset to keep track of what regression the coefficients/variances correspond to.
The solution suggest by Roberto Ferrer was working well on my test data, but turns out not to work so well on some other type of data. The reason is that my sample changes slightly from one regression to the next, and some factor variable does not take the same number of values in each regressions. This results in the fixed effects (created on the fly using i.myvar
as a regressor) not having the same cardinality.
Let's say that I decide to put year fixed effects (as in: year-specific intercepts) using i.year
but in one regression there is no observation for the year 2006. That means that this particular regression will have one fewer regressor (the dummy corresponding to year==2006 does not get created), and as a result a smaller matrix that stores the coeffs.
This results in a conformability error when trying to stack the matrices together.
I was wondering if there was a way to make the initial solution robust to varying number of regressors. (Perhaps saving each regressions as dta, then merging?)
I am still subject to the constraint that I cannot rely on external packages.