作者evilove (愿意感动就是一种享受)
看板Statistics
标题Re: [程式] Stata scalar 问题
时间Wed Feb 10 13:00:55 2021
解决了,方法如下:
local bi_var alzunit anymdex anyunit hospbase multifac profit
foreach v of varlist `bi_var' {
quietly summ `v'
scalar pop_mean = r(mean)
dis pop_mean
prtest `v' = `=pop_mean' if interested == 1
scalar drop pop_mean
}
※ 引述《evilove》之铭言:
: [程式问题]:
: 如何使用 scalar
: [软体熟悉度]:
: 熟悉
: [问题叙述]:
: 想要把一个变项的平均数(var_mean) pass给另外一个指令使用
: 但不晓得怎麽写
: dis var_mean 有看到 .9454545
: 但往下就fail了
: [程式范例]:
: . local bi_var alzunit anymdex anyunit hospbase multifac profit
: . foreach v of varlist `bi_var' {
: 2. quietly summ `v'
: 3. scalar define var_mean = r(mean)
: 4. dis var_mean
: 5. prtest `v' = var_mean if interested == 1
: 6. }
: .09454545
: var_mean is not a 0/1 variable
: r(450);
: 另一个写法
: . local bi_var alzunit anymdex anyunit hospbase multifac profit
: . foreach v of varlist `bi_var' {
: 2. tempvar var_mean
: 3. egen `var_mean' = mean(`v')
: 4. dis `var_mean'
: 5. prtest `v' = `var_mean' if interested == 1
: 6. }
: .09454545
: __000000 is not a 0/1 variable
: r(450);
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 69.140.102.182 (美国)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Statistics/M.1612933257.A.E6D.html
1F:→ diabolica: 自解 04/03 08:55