Is it possible to compute the cross-moment matrix of a set of variables, and then tell the -regress- command to use that matrix instead of re-calculating it again? This has two benefits. The first is for performance, but the second is that it allows me to ensure that any regression using a SUBSET of the variables in the cross-moment matrix is run over *precisely* the same sample. For example, if I build this data set:
and run two regressions:
these two regressions repeat some calculations internally and also use slightly different samples (because L4.unemp has one fewer observations than L3.unemp).
Note that the example in the documentation for -matrix accum- ( [P] matrix accum ) isn't helpful here because it's just the basic calculation of
not the more complex (and more useful) calculation that first calculates the cross-moment matrix and then uses it to estimate a regression involving a SUBSET of the variables in it instead of the entire matrix.
For example, in RATS, I can compute a cross-moment matrix using the CMOMENT command, and then tell LINREG to use that matrix when performing its calculation.
This guarantees that the regressions are run on *exactly* the same sample, and the cross-moment matrix isn't calculated multiple times.
Is this at all possible in Stata? This is an useful feature for applied time series work, especially in econometrics, in which model selection methods often require running similar regressions repeatedly, while guaranteeing that changes in the results are driven only by changes in the variables included, NOT by changes in the sample.
Code:
cls freduse UNRATE GDPC1, clear rename UNRATE unemp rename GDPC1 gdp gen t = qofd(daten) collapse (mean) unemp gdp, by(t) fast tsset t, q gen lgdp = log(gdp)
Code:
regress gdp L4.gdp L4.unemp regress gdp L4.gdp L3.unemp
Note that the example in the documentation for -matrix accum- ( [P] matrix accum ) isn't helpful here because it's just the basic calculation of
Code:
syminv(XX)*Xy
For example, in RATS, I can compute a cross-moment matrix using the CMOMENT command, and then tell LINREG to use that matrix when performing its calculation.
Code:
cmoment(noprint) # gdp{0 to 4} unemp{1 to 4} constant linreg(cmom, print) gdp # gdp{4} unemp{4} constant linreg(cmom, print) gdp # gdp{4} unemp{3} constant
Is this at all possible in Stata? This is an useful feature for applied time series work, especially in econometrics, in which model selection methods often require running similar regressions repeatedly, while guaranteeing that changes in the results are driven only by changes in the variables included, NOT by changes in the sample.
Comment