Hi,
I have a dataset in which I have the share price of different companies for every day for 10 years. I would like to create a variable that uses the share prices for every month and I am trying to do so with a loop. To do so, I created a new variable (date_01) with the end of month dates and I am trying to use this code below:
"levelsof date_01, local(lista_1)
foreach l of local lista_1 {
if date <= `l'[_n] & date > `l'[_n-1] {
whatever ...
}
}"
Where date is a variable containing the dates for all the daily observation. The dates are in this format 19960131. This code does not work because it says that the first observation in the date_01 variable, which is 19960131, is an invalid name.
Could you please give me some suggestions on how to fix the problem please?
Thank you.
I have a dataset in which I have the share price of different companies for every day for 10 years. I would like to create a variable that uses the share prices for every month and I am trying to do so with a loop. To do so, I created a new variable (date_01) with the end of month dates and I am trying to use this code below:
"levelsof date_01, local(lista_1)
foreach l of local lista_1 {
if date <= `l'[_n] & date > `l'[_n-1] {
whatever ...
}
}"
Where date is a variable containing the dates for all the daily observation. The dates are in this format 19960131. This code does not work because it says that the first observation in the date_01 variable, which is 19960131, is an invalid name.
Could you please give me some suggestions on how to fix the problem please?
Thank you.
Comment