Page 1 of 1

Controlling lag

Posted: Thu May 12, 2011 1:26 pm
by basil
I have the following series of market data: date, ticker, price, volume. The data is sorted by sym and date. There are two tickers in my sample: IBM and MSFT.
I would like to run the following regression for each ticker separately: equation ls. price c price(-1) volume volume(-1).
I planned to run a loop where each in iteration I restrict the sample:

for %ticker_now "IBM" "MSFT"
smpl if ticker=%ticker_now
equation ls. price c price(-1) volume volume(-1)
...
next

My problem is that when the regression runs for MSFT, the first observation of the explanatory variables price(-1) and volume(-1) has data for IBM, instead of being missing values.

Is there a quick solution for this erroneous data handling?

Of course, the above description is a simplification of the actual problem. For example, in my actual problem the number of lags varies from one loop to another and the number of tickers are in the thousands.

I very much appreciate any help.

Best,
Basile

Re: Controlling lag

Posted: Thu May 12, 2011 1:29 pm
by EViews Gareth
Probably the easiest thing to do is set the page up as a panel, with date as the time ID and ticker as the cross-section ID. EViews will know not to allow lags to cross tickers then.

Re: Controlling lag

Posted: Thu May 12, 2011 1:40 pm
by basil
will follow your advice.
(1) will this work if I have a non-balanced panel (i.e., not all sym have data for all date)?
(2) can I push forward the start of the sample, some thing like: smpl (if ticker=%ticker_now)+1 ???

Thanks for all your help

Re: Controlling lag

Posted: Thu May 12, 2011 1:50 pm
by EViews Gareth
1) Yes.
2) Don't understand the question.

Re: Controlling lag

Posted: Thu May 12, 2011 5:59 pm
by basil
you can do the following
smpl @first+1 @last

so, my question is whether I can do something similar, where I define my sample to be restricted to "smpl if ticker=%ticker_now" and then move the start of sample by one observation forward?

Re: Controlling lag

Posted: Thu May 12, 2011 7:03 pm
by EViews Gareth

Code: Select all

smpl @first+1 @last if ticker=%ticker_now

Re: Controlling lag

Posted: Fri May 13, 2011 6:02 am
by basil
The suggestion does not do the trick. It only offsets the beginning of the entire data by 1.

Assume IBM are observations 1 to 10, MSFT 11 to 20. Your suggestion will first restrict the data to observations 2 to 20, and then apply the "if" restriction. That means, "smpl @first+1 @last if ticker=%ticker_now" will give observations (2 to 10) and (11 to 20) for IBM and MSFT, respectively. I was looking to get observations (2 to 10) and (12 to 20) for IBM and MSFT, respectively. So, in essence, i would to first apply the "if" restriction, and then apply the offset by 1. Is that possible?

Thanks

Re: Controlling lag

Posted: Fri May 13, 2011 7:50 am
by EViews Gareth
No, it doesn't do that. See for example:

Code: Select all

create a 1990 2000 10 smpl @first+1 @last if crossid=3

Re: Controlling lag

Posted: Fri May 13, 2011 8:07 am
by basil
This definitely works for panel data, but not for non-panel stacked data.
thx

Re: Controlling lag

Posted: Fri May 13, 2011 8:38 am
by EViews Gareth
Probably the easiest thing to do is set the page up as a panel, with date as the time ID and ticker as the cross-section ID. EViews will know not to allow lags to cross tickers then.