Stata 命令将显示错误,因为glm
使用的语句指定了逻辑回归,结果为 1/0。您应该会看到一条错误消息“注意:PercentageFemale 具有非整数值。 ”但是,您的 R 命令已正确指定。
由于您没有提供数据,让我们从 R 中的一个可复制示例开始:
library(MASS)
data(menarche)
out <- glm(cbind(Menarche, Total-Menarche) ~ Age,
family=binomial(logit), data=menarche)
summary(out)
# Export into Stata data
library(foreign)
write.dta(menarche, "c:\\temp\\menarche.dta")
结果是:
[PRINTOUT SNIPPED FOR SPACE]
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -21.22639 0.77068 -27.54 <2e-16 ***
Age 1.63197 0.05895 27.68 <2e-16 ***
---
[PRINTOUT SNIPPED FOR SPACE]
现在,在 Stata 中复制它。首先让我们得到错误:
gen pm = Menarche / Total
glm pm Age, link(logit) family(binomial)
结果:
. glm pm Age, link(logit) family(binomial)
note: pm has noninteger values
[SNIPPED FOR SPACE]
AIC = .5990425
Log likelihood = -5.488031242 BIC = -73.81271
------------------------------------------------------------------------------
| OIM
pm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
Age | 1.608169 .6215021 2.59 0.010 .390047 2.826291
_cons | -20.91168 8.111063 -2.58 0.010 -36.80907 -5.014291
------------------------------------------------------------------------------
结果不同意。还要注意第 2 行的错误消息。
要让 Stata 与您的数据集格式对话,请使用blogit
. 请注意,在 R 中,它是yes 的数量和no 的数量;在Stata中,它是yes的数量,然后是总数:
blogit Menarche Total Age
以下是 R 的结果:
Logistic regression for grouped data Number of obs = 3918
LR chi2(1) = 3667.18
Prob > chi2 = 0.0000
Log likelihood = -819.65237 Pseudo R2 = 0.6911
------------------------------------------------------------------------------
_outcome | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
Age | 1.631968 .0589532 27.68 0.000 1.516422 1.747514
_cons | -21.22639 .7706859 -27.54 0.000 -22.73691 -19.71588
------------------------------------------------------------------------------