簡體   English   中英

通過Stata中的命令獲取值返回

[英]getting values return by commands in stata

我正在嘗試運行reg並獲取Stata數值。 我做了以下。 假設y是因變量, klmn是自變量,並且我創建了一個新變量new

loc vars k l m n
reg y `vars'

# I know that I can get back the coefficients using mat list e(b) but I  need to 
get coefficient of each variable and use it to compute the elasticity (one at a time).

# so, I run the following loop but it doesn't work.



foreach i in vars {
sca coeff`i' = _b[`i'] # main problem here 
sca cons = _b[_cons]  # main problem here
corr new `i' , c # correlation of new with each independent vars
sca cov_`i' = r(cov_12)
sum `i' 
sca elas_`i' = (coeff`i'*r(mean))/10 # elasticity not working 
}

在這方面的任何幫助將不勝感激。

作為神父 說,給定margins ,您不需要這樣做。 但是,為什么您的代碼不起作用? 您為foreach使用了錯誤的語法。

您不應該輸入

  foreach i in vars

  foreach i of local vars

否則,Stata將使用文字文本vars而不是本地宏vars的內容。 幫助中對這兩種語法進行了說明,並在http://www.stata-journal.com/sjpdf.html?articlenum=pr0005中進行了更詳細的說明

小點:

  1. 分配sca cons = _b[_cons]應該可以,但是您不必每次在循環中都重復一次。

  2. 您沒有向我們展示您用於生成new的代碼,因此我們必須假設這沒問題。

順便說一句,“無效”沒有太大意義。 我曾經整理了一份清單,列出了我遇到的大約20種含義,最重要的含義包括“非法”和“不做我想做的事情”。 因此,詳細說明發生的事情(在本例中為Stata響應時鍵入的內容)總是很有幫助的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM