- * Example generated by -dataex-. To install: ssc install dataex
- clear
- input byte(obs a b c)
- 1 1 4 .
- 2 2 5 12
- 3 3 6 13
- 4 . 7 11
- 5 5 8 .
- 6 6 9 18
- 7 7 . 20
- 8 8 . 21
- 9 9 12 23
- 10 10 13 .
- end
问题1:以下多种命令等产生的结果的某例(如样本例数)或某行怎么提取出来,或者生成矩阵?以供进一步计算。(tabstat除外)
- tabstat a b c, stat(N) col(stat)


问题2:采用矩阵的方法求某矩阵列或者行的计数?

最后的结果应该生成行向量或矩阵X = [10,9,8,7]
如以上为一个矩阵,欲求一行向量或矩阵记录每列的数量(当然能求列计数可转置得行计数),在stata里用命令很好求,在R和Python也很好求,但是怎么操作矩阵求呢?
问题3:npresent命令生成了我想要的结果
npresent[url=]附件[/url]

,但是命令的源代码太简单,如下:
*! 3.0.0 NJC 25 Sept 2003
program npresent, byable(recall)
version 8.0
syntax [varlist] [if] [in] [, * ]
marksample touse, novarlist
qui count if `touse'
if r(N) == 0 error 2000
nmissing `varlist' if `touse', `options' present
end
我提取后觉得是以下两句起作用
marksample touse, novarlist
qui count if `touse'
但是我单独执行得出的都是count的10的结果,没有排除缺失值,与npresent的结果(10,9,8,7)不一致?还有临时文件`touse'我打不开,__000000等临时文件怎么打开和调用呢?
dslocal vars `r(varlist)'di "`vars'"foreach v of local vars {marksample touse, novarlist count if `touse' di "`touse'"di "`ntouse'"}




雷达卡




京公网安备 11010802022788号







