Controlling lag
Posted: Thu May 12, 2011 1:26 pm
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
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