Dev Vencappa
> I probably failed to mention it but in a separate stage, I
> am appending all the 76 diferent files together into one
> file where I have the company code, it's optimal lag length
> (selected in a separate exercise based on AIC) and the
> dickey fuller statistic. When you mentioned that the
> results should belong together, you are right, except that
> the dickey fuller method does not seem to work on panel
> data. I have to keep the relevant company, tsset the data
> to year, and save the results (thus producing 76 different
> files, that I append together into one final file). The
> whole point behind this exercise is to compare individual
> unit root tests with panel unit root tests that I have
> computed for the same variables.
> I am copying the whole loop below. I am sure you will
> suggest a shorter way to write that.
>
> local z "netprem disclm elr solv"
> foreach k of local z{
> forvalues x=1/19{
> preserve
> keep if comcode==`x'
> tsset year
> postfile myhandledf lags`k' comcode dfstat`k' using
> "c:\unitroot\dfunitrootlag`k'comp`x'", replace
> summ AICoptlag`k' if comcode==`x', mean
> dfuller `k', lags(`r(mean)') reg
> scalar LAGS`k'=AICoptlag`k'
> scalar DFSTAT`k'=r(Zt)
> post myhandledf (LAGS`k') (`x') (DFSTAT`k')
> postclose myhandledf
> restore
> }
> postutil clear
> }
>
> local z "netprem disclm elr solv"
> foreach k of local z{
> use "c:\unitroot\dfunitrootlag`k'comp1", clear
> forvalues x = 2/19 {
> append using "c:\unitroot\dfunitrootlag`k'comp`x'"
> }
> save "c:\unitroot\dfunitrootlag`k'allcomp", replace
> }
>
> use "c:\unitroot\dfunitrootlagnetpremallcomp", clear
> local z "disclm elr solv"
> foreach k of local z{
> joinby comcode using "c:\unitroot\dfunitrootlag`k'allcomp"
> }
> save "c:\unitroot\dfunitrootlagallcomp", replace
>
I don't think I need to suggest it,
as you seem only a smidgen away from it in your code.
Just send everything to one file making sure
that everything is explicit, not explicit.
That is, you want to post company, year
and the two scalars produced by -dfuller-,
each set of four being one line of a file.
Nick
[email protected]
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/