| 老师们好!
请帮忙解决循环只执行一次,不能向下执行的问题。谢谢您!到第二个g,drop后的 (g==`t') 就不能变化执行了。试了,不是drop不满足条件中断。
请问这个命令因为什么问题,g=1执行之后就不能执行了呢?g=2更改为符合条件的也不能执行?谢谢
解决的问题:同一公司年度有多个s0701a==1或s0701a==2的seperation值,保留唯一seperation值。
第一步,s0701a==1,seperation不缺失,删除s0701a=2的所有行观测值;然后取s0701a==1,seperation的均值,保留一个seperation值。
第二步,s0701a==1,seperation缺失,删除s0701a==1的所有行观测值;然后取s0701a==2,seperation的均值,保留一个seperation值。
数据如下: 1. * Example generated by -dataex-. To install: ssc install dataex 2. clear 3. input str10 codeyear byte s0701a double seperation byte r_tag double(g seperation0 seperation1) 4. "0000012003" 1 0 1 1 . . 5. "0000012003" 2 0 1 1 0 . 6. "0000012004" 1 . 4 2 . . 7. "0000012004" 2 . 4 2 . . 8. "0000012004" 2 . 4 2 . . 9. "0000012004" 2 . 4 2 . . 10. "0000012004" 2 . 4 2 . . 11. "0000012016" 1 . 1 3 . . 12. "0000012016" 2 4.0318 1 3 4.0318 . 13. "0000012017" 2 4.0696 1 4 4.0696 . 14. "0000042020" 1 6.8294 2 5 . . 15. "0000042020" 2 3.9358 2 5 3.4147 . 16. "0000042020" 2 2.8936 2 5 3.4147 . 17. "6030002013" 1 0 0 6 . . 18. "6038832015" 1 0 3 7 . . 19. "6038832015" 1 .2434 3 7 . . 20. "6038832015" 1 0 3 7 . . 21. "6038832015" 2 10.6729 3 7 10.6729 . 22. end 复制代码
不完整的循环命令,不能执行一次后不能执行:
import excel using 示例, firstrow case(lower) clear
labone , nrow(1)
compress
browse
sort codeyear s0701a
egen g=group(codeyear ) // g分组
sum g
bys codeyear: egen seperation0=mean(seperation) if s0701a==2
gen seperation1=.
cap label variable year "年度"
cap label variable codeyear "代码年度,唯一标识"
cap label variable seperation "两权分离率(%)_没有单位"
cap label variable s0701a "1=年报中公布,2=根据股权控制链计算所得"
cap label variable r_tag " codeyear 重复次数"
dataex
forvalues t=1/7 {
set trace on
if (g==`t') & (s0701a==1) & (seperation!=. ){
drop if (g==`t') & (s0701a==2)
}
|