Hello!!
I have a panel dataset which consists of the following variables:
ddate=daily date, mdate=monthly date, stockName= stock Id, dExReturn= each stock's daily excess return and mktexcess= market's portfolio excess return.
I would like to calculate the the monthly market beta for each stock, using daily data in a rolling window of 12 months for each stock(months t-11 through t, inclusive) with a minimum requirement of 200 valid daily return observations during the calculation period.
I use the following command :
xtset stockName ddate
rangestat (reg) dExReturn mktexcess if [_n]>=200 , interval(mdate -11 0) by(stockName ddate)
but i get the following error: no result for all obs: reg dExReturn mktexcess
If i use rangestat (reg) dExReturn mktexcess if [_n]>=200 , interval(mdate -11 0) by(stockName mdate), I get very few Nobs for my regression (22-25 in each case). Actually the program seems like estimating betas in a 12 month period using a rolling window of 1 month instead of a 12month one. Am I doing something wrong? if not, does anyone know how can I overcome this problem in the first regression?
I read somewhere that _n maybe is not appropriate for counting how many observations are being used. If this is true, what can i do in order to specify the number of observations used in a regression or in any stata operation/calculation in general?
I have a panel dataset which consists of the following variables:
ddate=daily date, mdate=monthly date, stockName= stock Id, dExReturn= each stock's daily excess return and mktexcess= market's portfolio excess return.
I would like to calculate the the monthly market beta for each stock, using daily data in a rolling window of 12 months for each stock(months t-11 through t, inclusive) with a minimum requirement of 200 valid daily return observations during the calculation period.
I use the following command :
xtset stockName ddate
rangestat (reg) dExReturn mktexcess if [_n]>=200 , interval(mdate -11 0) by(stockName ddate)
but i get the following error: no result for all obs: reg dExReturn mktexcess
If i use rangestat (reg) dExReturn mktexcess if [_n]>=200 , interval(mdate -11 0) by(stockName mdate), I get very few Nobs for my regression (22-25 in each case). Actually the program seems like estimating betas in a 12 month period using a rolling window of 1 month instead of a 12month one. Am I doing something wrong? if not, does anyone know how can I overcome this problem in the first regression?
I read somewhere that _n maybe is not appropriate for counting how many observations are being used. If this is true, what can i do in order to specify the number of observations used in a regression or in any stata operation/calculation in general?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(ddate mdate) int stockName float(mktexcess dExReturn) 13030 428 1 -1.29 . 13081 429 1 .52 . 13065 429 1 -.99 . 13068 429 1 .94 . 13060 429 1 .32 . 13083 429 1 .15 . 13067 429 1 .42 . 13079 429 1 -2.66 . 13069 429 1 -.59 . 13075 429 1 -.56 . 13062 429 1 -.47 . 13061 429 1 -.3 . 13073 429 1 -.89 . 13066 429 1 -1.1 . 13058 429 1 -.76 . 13059 429 1 -.7 . 13086 429 1 -.04 . 13082 429 1 2.31 . 13076 429 1 -2.79 . 13072 429 1 -2 . 13074 429 1 1.56 . 13087 429 1 1.66 . 13080 429 1 1.45 . 13116 430 1 -1.31 -.17647076 13117 430 1 -.02 -.1684661 13090 430 1 -.78 . 13104 430 1 .16 . 13111 430 1 -.74 . 13093 430 1 -.94 . 13110 430 1 -.68 . 13088 430 1 -.02 . 13114 430 1 .49 . 13107 430 1 -.4 . 13100 430 1 -.36 . 13108 430 1 .03 . 13103 430 1 1.05 . 13094 430 1 .22 . 13101 430 1 -.52 . 13097 430 1 -.82 . 13115 430 1 -1.23 . 13102 430 1 .74 . 13095 430 1 1.08 . 13096 430 1 -2.14 . 13109 430 1 .03 . 13089 430 1 .73 . 13118 431 1 -.23 -4.1254034 13121 431 1 -.79 -2.2510245 13138 431 1 1.28 -1.452436 13145 431 1 .1 -.40043905 13144 431 1 2.05 -.26010343 13124 431 1 1.11 -.25598717 13130 431 1 -.58 -.1774432 13142 431 1 .04 -.02 13135 431 1 -.93 .06097699 13125 431 1 -.01 .08137292 13143 431 1 .09 .2440338 13128 431 1 .51 .461053 13146 431 1 .19 .5333526 13132 431 1 2.27 1.1266963 13139 431 1 .46 1.1347535 13131 431 1 .4 1.30791 13129 431 1 .88 1.3406608 13122 431 1 -.2 1.8126007 13136 431 1 .07 2.0351832 13137 431 1 -1.33 2.3743525 13123 431 1 1.69 2.636169 13174 432 1 -1.37 -2.591869 13163 432 1 -1.76 -2.5359194 13170 432 1 -1.5 -1.9956445 13152 432 1 -1.41 -1.0611887 13158 432 1 -.79 -.8844621 13153 432 1 -.94 -.6853262 13173 432 1 -.84 -.4321569 13165 432 1 -.24 -.3024822 13171 432 1 .17 -.1687522 13159 432 1 -.23 -.14132519 13149 432 1 -.02 -.02 13160 432 1 -.09 .16220886 13151 432 1 -.11 .1717619 13179 432 1 1.11 .18535297 13150 432 1 1.84 1.0263423 13172 432 1 .35 1.1791663 13177 432 1 .62 1.6715692 13178 432 1 1.49 1.6881968 13157 432 1 .25 1.7160083 13164 432 1 1.36 1.799027 13156 432 1 .87 1.8180068 13166 432 1 2.15 2.1544096 13167 432 1 2.55 2.767562 13193 433 1 -4.33 -5.159505 13191 433 1 -2.61 -2.631725 13194 433 1 -.93 -1.8937757 13198 433 1 -1.58 -1.64815 13195 433 1 -1.5 -1.3744533 13208 433 1 -.56 -1.3032315 13205 433 1 -1.03 -1.0833682 13184 433 1 -.52 -.9121054 13199 433 1 -.76 -.7140765 13186 433 1 -.06 -.1472033 13188 433 1 .3 .1969484 end format %td ddate format %tm mdate
Comment