STATA: _n _N 应用 理解排序?

webuse dollhill2, clear
  gen n = _n
  gen N = _N  
如果想要统计各个不同的年龄段中共多少人吸烟:

by age (smokes), sort: generate wgta=pyears[_N]
.  by age (smokes), sort: generate wgt1=pyears[_n]

webuse dollhill2, clear
  gen n = _n
  gen N = _N  
bys age smokes:  generate wgt=pyears[_N]

webuse dollhill2, clear
  gen n = _n
  gen N = _N  
bys age(smokes):  generate wgt=pyears[_N]

webuse dollhill2, clear
  gen n = _n
  gen N = _N  
bys age:  generate wgt=pyears[_N]

 

posted @ 2023-03-15 15:51  myrj  阅读(145)  评论(0编辑  收藏  举报