下的是股票两年的月度数据。想判断每只股票在month=10,11,。。。24时,某月的换手率是否为包括该月及之前9个月的最大值,标记为flag1=1;类似的,若为最小值则标记为flag2=1。写了如下的循环:
. local t
. gen flag1=0
. gen flag2=0
. forvalues t=10/24{
2. bysort stockcode:replace flag1=(month==t)&(to==max(to[t-9],to[t-8],to[t-7],to[t-6],to[t-5],to[t-4],to[t-3],to[t-2],to[t-1],to[t]))
3. bysort stockcode:replace flag2=(month==t)&(to==min(to[t-9],to[t-8],to[t-7],to[t-6],to[t-5],to[t-4],to[t-3],to[t-2],to[t-1],to[t]))
4. }
但是结果是flag1和flag2都没变,请问是调用max和min函数出了问题吗?
还有,求10个换手率均值的表达式是否可以简略一些表达,我试过to in t-9/t 不行?
初学stata,多谢解答!~~