3

xtlogit在使用命令运行多级回归后,我尝试计算 Stata 12 中变量的边距。但是,尽管我margins在运行回归后立即使用了该命令,但仍然收到错误消息,说我的变量未在协变量列表中找到。这是我的代码的简化版本:

. use http://url.com/file.dta, clear
. xtset country
. xtlogit dv iv1 iv2 iv3 iv4 iv5
. margins iv1, at(iv2==(0(1)6))
'iv1' not found in list of covariates
r(322);

margins有趣的是,当我以需要逗号的格式使用命令时,Stata 没有给出任何错误。例如,以下两行代码没有任何问题:

margins, at(iv2=(0(1)6)) over(iv1)
margins, dydx(iv1) at(iv2=(0(1)6))

我从 2013 年 3 月看到了这篇上一篇文章,但我仍然无法弄清楚如何解决这个问题:Stata 错误:未在协变量列表中找到

4

1 回答 1

1

你能用公共数据集重现错误吗?这是我的尝试(底部有因子变量解决方案):

. use http://www.stata-press.com/data/r13/union
(NLS Women 14-24 in 1968)

. xtlogit union age grade not_smsa south##c.year

Fitting comparison model:

Iteration 0:   log likelihood =  -13864.23  
Iteration 1:   log likelihood = -13547.326  
Iteration 2:   log likelihood = -13542.493  
Iteration 3:   log likelihood =  -13542.49  
Iteration 4:   log likelihood =  -13542.49  

Fitting full model:

tau =  0.0     log likelihood =  -13542.49
tau =  0.1     log likelihood = -12923.751
tau =  0.2     log likelihood = -12417.651
tau =  0.3     log likelihood = -12001.665
tau =  0.4     log likelihood = -11655.586
tau =  0.5     log likelihood = -11366.441
tau =  0.6     log likelihood = -11128.749
tau =  0.7     log likelihood = -10946.399
tau =  0.8     log likelihood = -10844.833

Iteration 0:   log likelihood = -10946.488  
Iteration 1:   log likelihood =  -10557.39  
Iteration 2:   log likelihood = -10540.493  
Iteration 3:   log likelihood = -10540.274  
Iteration 4:   log likelihood = -10540.274  (backed up)
Iteration 5:   log likelihood = -10540.274  

Random-effects logistic regression              Number of obs      =     26200
Group variable: idcode                          Number of groups   =      4434

Random effects u_i ~ Gaussian                   Obs per group: min =         1
                                                               avg =       5.9
                                                               max =        12

Integration method: mvaghermite                 Integration points =        12

                                                Wald chi2(6)       =    227.46
Log likelihood  = -10540.274                    Prob > chi2        =    0.0000

------------------------------------------------------------------------------
       union |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         age |   .0156732   .0149895     1.05   0.296    -.0137056     .045052
       grade |   .0870851   .0176476     4.93   0.000     .0524965    .1216738
    not_smsa |  -.2511884   .0823508    -3.05   0.002    -.4125929   -.0897839
     1.south |  -2.839112   .6413116    -4.43   0.000    -4.096059   -1.582164
        year |  -.0068604   .0156575    -0.44   0.661    -.0375486    .0238277
             |
south#c.year |
          1  |   .0238506   .0079732     2.99   0.003     .0082235    .0394777
             |
       _cons |  -3.009365   .8414963    -3.58   0.000    -4.658667   -1.360062
-------------+----------------------------------------------------------------
    /lnsig2u |   1.749366   .0470017                      1.657245    1.841488
-------------+----------------------------------------------------------------
     sigma_u |   2.398116   .0563577                      2.290162    2.511158
         rho |   .6361098   .0108797                      .6145307    .6571548
------------------------------------------------------------------------------
Likelihood-ratio test of rho=0: chibar2(01) =  6004.43 Prob >= chibar2 = 0.000

. margins not_smsa, at(age=(10(5)20))
'not_smsa' not found in list of covariates
r(322);

. xtlogit union age grade i.not_smsa i.south##c.year

Fitting comparison model:

Iteration 0:   log likelihood =  -13864.23  
Iteration 1:   log likelihood = -13547.326  
Iteration 2:   log likelihood = -13542.493  
Iteration 3:   log likelihood =  -13542.49  
Iteration 4:   log likelihood =  -13542.49  

Fitting full model:

tau =  0.0     log likelihood =  -13542.49
tau =  0.1     log likelihood = -12923.751
tau =  0.2     log likelihood = -12417.651
tau =  0.3     log likelihood = -12001.665
tau =  0.4     log likelihood = -11655.586
tau =  0.5     log likelihood = -11366.441
tau =  0.6     log likelihood = -11128.749
tau =  0.7     log likelihood = -10946.399
tau =  0.8     log likelihood = -10844.833

Iteration 0:   log likelihood = -10946.488  
Iteration 1:   log likelihood =  -10557.39  
Iteration 2:   log likelihood = -10540.493  
Iteration 3:   log likelihood = -10540.274  
Iteration 4:   log likelihood = -10540.274  (backed up)
Iteration 5:   log likelihood = -10540.274  

Random-effects logistic regression              Number of obs      =     26200
Group variable: idcode                          Number of groups   =      4434

Random effects u_i ~ Gaussian                   Obs per group: min =         1
                                                               avg =       5.9
                                                               max =        12

Integration method: mvaghermite                 Integration points =        12

                                                Wald chi2(6)       =    227.46
Log likelihood  = -10540.274                    Prob > chi2        =    0.0000

------------------------------------------------------------------------------
       union |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         age |   .0156732   .0149895     1.05   0.296    -.0137056     .045052
       grade |   .0870851   .0176476     4.93   0.000     .0524965    .1216738
  1.not_smsa |  -.2511884   .0823508    -3.05   0.002    -.4125929   -.0897839
     1.south |  -2.839112   .6413116    -4.43   0.000    -4.096059   -1.582164
        year |  -.0068604   .0156575    -0.44   0.661    -.0375486    .0238277
             |
south#c.year |
          1  |   .0238506   .0079732     2.99   0.003     .0082235    .0394777
             |
       _cons |  -3.009365   .8414963    -3.58   0.000    -4.658667   -1.360062
-------------+----------------------------------------------------------------
    /lnsig2u |   1.749366   .0470017                      1.657245    1.841488
-------------+----------------------------------------------------------------
     sigma_u |   2.398116   .0563577                      2.290162    2.511158
         rho |   .6361098   .0108797                      .6145307    .6571548
------------------------------------------------------------------------------
Likelihood-ratio test of rho=0: chibar2(01) =  6004.43 Prob >= chibar2 = 0.000


. margins not_smsa, at(age=(10(5)20))

Predictive margins                                Number of obs   =      26200
Model VCE    : OIM

Expression   : Linear prediction, predict()

1._at        : age             =          10

2._at        : age             =          15

3._at        : age             =          20

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
_at#not_smsa |
        1 0  |  -2.674903   .3107206    -8.61   0.000    -3.283905   -2.065902
        1 1  |  -2.926092   .3148551    -9.29   0.000    -3.543196   -2.308987
        2 0  |  -2.596538   .2375601   -10.93   0.000    -3.062147   -2.130928
        2 1  |  -2.847726   .2432156   -11.71   0.000     -3.32442   -2.371032
        3 0  |  -2.518172   .1660016   -15.17   0.000    -2.843529   -2.192814
        3 1  |   -2.76936   .1743793   -15.88   0.000    -3.111137   -2.427583
------------------------------------------------------------------------------
于 2013-07-15T22:00:46.050 回答