Dear all,
I have panel data comprising of firms and daily stock returns. The returns of the firms are called pch. The firm_month is a group(firm month) variable. I have declared my data as panel data: tsset firmn day. (firmn is just the encoded firm variable and is omitted for brevity).
Every month, I want to calculate the skewness of the variable pch based on the previous 252 days. To give you an idea, I show below how the variable skewness want to look like. For example for the firm de0007459331 in month 102, the skewness is calculated by taking into account the pch in day 2121 and in the previous 251 days.
After doing my research, I found that these 2 links are the closest to what I want to do, but the questions posed are not answered explicitly.
http://www.stata.com/statalist/archi.../msg00825.html
http://www.statalist.org/forums/foru...ndows-in-panel
The command that I tried is:
But apart from its efficiency, I doubt also about the syntax.
A simple one line command that does this is welcome, because I want to understand the intuition.
But because I have a large dataset, any answers that use Mata or rangestat and thus make the process more efficient would be more than welcome.
Below, I show you an example of my dataset of a firm for two months (21 trading days each that may contain also missings).
Thank you in advance for your help,
Dimitris Chlorokostas
I have panel data comprising of firms and daily stock returns. The returns of the firms are called pch. The firm_month is a group(firm month) variable. I have declared my data as panel data: tsset firmn day. (firmn is just the encoded firm variable and is omitted for brevity).
Every month, I want to calculate the skewness of the variable pch based on the previous 252 days. To give you an idea, I show below how the variable skewness want to look like. For example for the firm de0007459331 in month 102, the skewness is calculated by taking into account the pch in day 2121 and in the previous 251 days.
After doing my research, I found that these 2 links are the closest to what I want to do, but the questions posed are not answered explicitly.
http://www.stata.com/statalist/archi.../msg00825.html
http://www.statalist.org/forums/foru...ndows-in-panel
The command that I tried is:
Code:
rolling pch, window(252) stepsize(21): egen skewness = skew(pch)
A simple one line command that does this is welcome, because I want to understand the intuition.
But because I have a large dataset, any answers that use Mata or rangestat and thus make the process more efficient would be more than welcome.
Below, I show you an example of my dataset of a firm for two months (21 trading days each that may contain also missings).
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str14 firm float(day month firm_month pch skewness) "de0007459331" 2101 101 19253 -.0261 .04761905 "de0007459331" 2102 101 19253 0 .04761905 "de0007459331" 2103 101 19253 0 .04761905 "de0007459331" 2104 101 19253 -.0327 .04761905 "de0007459331" 2105 101 19253 0 .04761905 "de0007459331" 2106 101 19253 0 .04761905 "de0007459331" 2107 101 19253 .0246 .04761905 "de0007459331" 2108 101 19253 0 .04761905 "de0007459331" 2109 101 19253 .0285 .04761905 "de0007459331" 2110 101 19253 .0015 .04761905 "de0007459331" 2111 101 19253 0 .04761905 "de0007459331" 2112 101 19253 .0204 .04761905 "de0007459331" 2113 101 19253 -.0186 .04761905 "de0007459331" 2114 101 19253 -.0029 .04761905 "de0007459331" 2115 101 19253 -.0073 .04761905 "de0007459331" 2116 101 19253 -.0441 .04761905 "de0007459331" 2117 101 19253 -.0154 .04761905 "de0007459331" 2118 101 19253 .0469 .04761905 "de0007459331" 2119 101 19253 .0149 .04761905 "de0007459331" 2120 101 19253 .0147 .04761905 "de0007459331" 2121 101 19253 0 .04761905 "de0007459331" 2122 102 19254 -.0145 .05823654 "de0007459331" 2123 102 19254 .0221 .05823654 "de0007459331" 2124 102 19254 -.0115 .05823654 "de0007459331" 2125 102 19254 -.0218 .05823654 "de0007459331" 2126 102 19254 -.003 .05823654 "de0007459331" 2127 102 19254 0 .05823654 "de0007459331" 2128 102 19254 -.0075 .05823654 "de0007459331" 2129 102 19254 -.0226 .05823654 "de0007459331" 2130 102 19254 0 .05823654 "de0007459331" 2131 102 19254 .0231 .05823654 "de0007459331" 2132 102 19254 -.0075 .05823654 "de0007459331" 2133 102 19254 0 .05823654 "de0007459331" 2134 102 19254 -.003 .05823654 "de0007459331" 2135 102 19254 0 .05823654 "de0007459331" 2136 102 19254 .0015 .05823654 "de0007459331" 2137 102 19254 -.0061 .05823654 "de0007459331" 2138 102 19254 .0076 .05823654 "de0007459331" 2139 102 19254 -.0061 .05823654 "de0007459331" 2140 102 19254 .0061 .05823654 "de0007459331" 2141 102 19254 0 .05823654 "de0007459331" 2142 102 19254 -.0061 .05823654 end
Thank you in advance for your help,
Dimitris Chlorokostas
Comment