Hi there,

I need to create lagged variables to run as part of a Fama-MacBeth regression, and asreg doesn't seem to like L.variable formats. So I am creating them individually.

I have financial data by permanent number (permno) and also date (1963m7 to 2018m12). Some of this information is annual data, matched for the specific company for all 12 months of each fiscal year. So CAPEX for permno 10001 is the same for all months of 1986 when the financial year ends in December, for example.

When I try to create one month (frequency is monthly, 1 period) lags, it will use the previous month, which is not what I want. I also can't use lags of 12 months, because that will not create a lag from the last year's financial statement data.

I need a command that says if the CAPEX value for a month (t) is different to the CAPEX value of the next month (t+1), use the value of CAPEX for month t as the lagged value for each of the next 12 months (t+1 through t+12), and then it'll repeat the process for the following financial year. I need to run this by permno too. The best I have come up with is: by permno: gen capex_lag=L.capex. Something using an if statement that checks for unique consecutive observations?

Thank you for your help.

Scott