[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: save coeff estimators of Arima model with foreach

From   "Martin Weiss" <>
To   <>
Subject   st: Re: save coeff estimators of Arima model with foreach
Date   Thu, 12 Mar 2009 01:21:42 +0100


I cannot see what is inherently wrong in your code. If others want to check my reasoning, it is pretty much equivalent to

sysuse auto, clear
g coeffs=.
qui levelsof rep78, loc(levels)
qui foreach l of local levels {
    reg pr we f tr if rep == `l'
    replace coeffs= _b[tr] if rep == `l'
sort rep
l coef rep78, noo sepby(rep)

which does work, and is itself equivalent to the easier

statsby _b[tr], by(rep78) clear : reg pr we f tr

though that -after your confirmation- destroys your dataset in memory.

So you say that you have checked you can run these commands on the entire sample. That need not mean much. Rather, pick out some level of your gvkey randomly and run the thing with the if-statements present. Try that for a couple of these levels to get a flavor of what is going on and report the results back to the list...

----- Original Message ----- From: "Hua Pan" <>
To: <>
Sent: Wednesday, March 11, 2009 11:42 PM
Subject: st: save coeff estimators of Arima model with foreach

Hi statalisters,

I’m a beginner for Stata, and I have just a problem with it. I want to do a cross-sectional time series analysis with command “arima” and imput the estimator of “AR L1. Coefficient” of every panel data into the datasheet with the help of “foreach” and “levelsof”.

My Data looks like this:
gvkey      qtl         eps
1 2003q1        ….
1       2003q2        ….
1       2003q3        ….
...       …….
2       2003q1
2       2003q2
2       2003q3
gvkey:  identify-Nr. of firms (panel variable, long)
qtl:     quarter (time variable, float)
eps:    earnings per share (dependent variable, float)

So I’ve tried:

- generate AR =.
tsset gvkey qtl
levelsof gvkey, local(levels)
foreach l of local levels {
arima eps if gvkey == `l', arima(1,0,0) sarima(0,1,0,4)
replace AR = _b[] if gvkey == `l'

But it doesn’t seem to work. Time series analysis (Arima) hasn’t been done and all of AR are still missing value.
I’m sure this is correct:
- arima eps, arima(1,0,0) sarima(0,1,0,4)
- replace AR = _b[]
I’ve tried it for data with one Observation (one gvkey)

I guess, there may be something wrong with foreach or levelsof, but I can’t find the error. Can anyone here give me any advice?
Any help would be greatly appreciated. Thanks in advance for your time.
I’m using Stata version 10.1 SE (Windows).

Best Regards

Hua Pan
University of Cologne

Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen:
*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2021 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index