Stata以及如何在回归中使用局部变量

问题描述 投票:0回答:1

我有两组变量来解释结果(运动和大小),我有兴趣发现预测结果的哪一部分属于哪一组。 local motor可以包含1个或多个变量。为此,我需要一个代码,该代码可以了解motor中的哪些变量,并将它们的影响添加到一个名为predict_motor_smart的变量中。在此示例中,predict_motor_smart应等于predict_motor。从本质上讲,我需要为代码的最后一行找到一个表达式,该表达式对于更改local motor变量的规范具有鲁棒性。

sysuse auto, clear

local outcome "price"

local  motor "mpg rep78"

local  size "weight length"

regress `outcome' `motor' `size'

gen predict_motor = _b[_cons] + mpg * _b[mpg] + rep78*_b[rep78]

 * gen predict_motor_smart = _b[_cons] + var1  of motor * beta 1 of motor + var2 of motor * beta2 of motor
variables regression stata local
1个回答
0
投票
 sysuse auto, clear
 local outcome "price"
 local  motor "mpg rep78"
 local  size "weight length"
 regress `outcome' `motor' `size'
 predict outcome_predict
 gen predict_motor = .
 replace predict_motor = _b[_cons] + mpg * _b[mpg] + rep78*_b[rep78] if 
 outcome_predict!=.
 gen predict_motor_smart =.
 replace predict_motor_smart   = _b[_cons] if outcome_predict!=.
 foreach l of local circumstances{
 replace predict_motor_smart  = predict_motor_smart  +`l'*_b[`l']
   }
© www.soinside.com 2019 - 2024. All rights reserved.