Dear all,
I have a dataset in wide format with stock tickers, date, and price of the stock. I am trying to generate dummy variables that mark each time period e.g. between 1995m7-1996m6, 1996m7-1997m6 and so on. I worked 1995m7-1996m6 period individually and the code does exactly what I want. I am just trying to loop from 1995-2016. Here is what I have in terms of code and Stata error message:
forval n=1995/2016 {
gen ind`n'=0
gen panel`n'=0
replace ind`n'=1 if date>=tm(`n'm7) & date<=tm(`n'+1m6)
by ticker : egen sum`n' = total( ind`n' ) if ind`n'==1
replace panel`n'=1 if sum`n' ==12
}
tm(1995+1m6) invalid
r(198);
I am puzzled since if I run the code with `n'+1 below I get what I want:
forval n=1995/2016 {
2. display `n'+1
3.
. }
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
I would appreciate any help with this.
Thanks in advance.
I have a dataset in wide format with stock tickers, date, and price of the stock. I am trying to generate dummy variables that mark each time period e.g. between 1995m7-1996m6, 1996m7-1997m6 and so on. I worked 1995m7-1996m6 period individually and the code does exactly what I want. I am just trying to loop from 1995-2016. Here is what I have in terms of code and Stata error message:
forval n=1995/2016 {
gen ind`n'=0
gen panel`n'=0
replace ind`n'=1 if date>=tm(`n'm7) & date<=tm(`n'+1m6)
by ticker : egen sum`n' = total( ind`n' ) if ind`n'==1
replace panel`n'=1 if sum`n' ==12
}
tm(1995+1m6) invalid
r(198);
I am puzzled since if I run the code with `n'+1 below I get what I want:
forval n=1995/2016 {
2. display `n'+1
3.
. }
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
I would appreciate any help with this.
Thanks in advance.
Comment