作者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/m.aspx?n=bbs/Statistics/M.1612933257.A.E6D.html
1F:→ diabolica: 自解 04/03 08:55