Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: RE: RE: RE: RE: RE: RE: RE: Foreach Command in Panel Data

From   "Degas Wright" <>
To   <>
Subject   st: RE: RE: RE: RE: RE: RE: RE: Foreach Command in Panel Data
Date   Wed, 29 Sep 2010 11:35:47 -0400

Thank you for the reference to 8/05 FAQ and it worked great for
calculating the var for my dataset. A follow on question, I have been
unsuccessful getting the fcast command to work. I have tried
incorporating it into the original forvalue step and doing a separate
forvalue step but neither works.

. forvalues xticker=1/`r(max)'{
.   var r ep mom if xticker==`xticker'

Works fine, however; when I do the following:

. forvalues xticker =1/`r(max)'{
.    fcast compute f_, step(3) if xticker==`xticker'

I get the following error:

Invalid syntax r(198)

I need to perform the var step first and then I can use the fcast
command.  Also, to address your question on collating the results - I
will upload the xtickers, forecasted values (f_r), dates into another
software package to run backtests on how well the forecasted values
perform in a portfolio selection process.

Again thank you for your assistance.

Degas A. Wright, CFA
Chief Investment Officer
Decatur Capital Management, Inc.
250 East Ponce De Leon Avenue, Suite 325
Decatur, Georgia  30030
Voice: 404.270.9838
-----Original Message-----
[] On Behalf Of Nick Cox
Sent: Tuesday, September 28, 2010 4:12 PM
To: ''
Subject: st: RE: RE: RE: RE: RE: RE: Foreach Command in Panel Data

I can't add much to my earlier emphasis given your report. Quite what
does "not interpreting the data as time series" mean? Please bear in
mind the age-old injunction on this list:

"Say exactly what you typed and exactly what Stata typed (or did) in
response. N.B. exactly! If you can, reproduce the error with one of
Stata's provided datasets or a simple concocted dataset that you include
in your posting."

Otherwise, your report will seem only a short distance away from "I am
getting results I do not understand. Can anyone explain why?". 

However, you might also look at 

FAQ     . . . . . .  Dealing with reports of repeated time values within
        . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox and M.
        12/05   How do I deal with a report of repeated time values
                within panel?


Degas Wright

For some reason the tsset is not interpreting the data as time series
and the data has to be in a time series for the var to work.  That is
another reason that I have to handle one ticker at a time or the tsset
command identifies the data as panel.

Thanks for the FAQ reference.

Nick Cox

I see. 

An FAQ very recently referred to 

FAQ     . . . . . . . . . . Making foreach go through all values of a
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N.
J. Cox
        8/05    Is there a way to tell Stata to try all values of a
                particular variable in a foreach statement without
                specifying them?

gives some guidance. You are going to need to select a panel each time
you go through the loop. On the other hand, producing 2000 sets of
results does raise the question of how you are going to collate them. 


Degas Wright

So I am attempting to isolate each stock to determine the impact of
various fundamental variables on excess returns by using the var time
series command.  When I have one stock in the dataset and use the tsset
date command, then use the var command, it works fine.  I am attempting
to write a program that select one ticker at a time to run the time
series from my panel data.  

Your point on isolating a single stock is exactly our objective since
cross sectional approach contains a significant amount of noise in the

Nick Cox

Actually, it's interesting that this gets past 

foreach xticker in dcm.dfa1.dat {

but the reason is that you never refer to `xticker' within the loop.
Thus another problem with this loop is that it would never repeat


Nick Cox

If it's panel data, the appropriate -tsset- specifies both identifier
and time variable. Without a panel identifier, the report you get is, if
you think more about it, what you should expect. 

The deeper issue of whether it makes scientific sense to forecast stocks
in isolation is not one I can usefully comment on. 

Degas Wright

I have panel data of 2000 tickers, excess returns (r) and various
fundamental variables such as earnings yield (ep), momentum(mom),
earnings revision (rev), over a 120 month period.  I am trying to use
the var command to develop a time series forecast for each individual
stock's excess return.  I realize that I have to analyze one ticker
(stock) at a time with the time series approach and assumed that using
the foreach command would work.

       panel variable:  xticker (unbalanced)
        time variable:  date, 2000m2 to 2009m6, but with gaps
                delta:  1 month

foreach xticker in dcm.dfa1.dat{
  2. tsset date
  3. var r ep mom rev
  4. }
repeated time values in sample

However, I get the repeated time values in sample r(451).

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index