2013-07-15 594 views
3

我試圖在使用xtlogit命令運行多級迴歸之後,計算Stata 12中變量的邊距。但是,雖然我在運行迴歸後立即使用margins命令,但我仍然收到一個錯誤,說我的變量未在協變量列表中找到。這裏是我的代碼的簡化版本:當使用「邊距」命令時,Stata中的變量「未在協變量列表中找到」錯誤

. 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命令給任何錯誤。例如,代碼工作的以下兩行沒有任何問題:

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

我已經看到了從2013年3月這個以前的帖子,但我仍然想不通我怎麼能解決這個問題:Stata error: not found in list of covariates

+0

你能描述一下你想在'(iv2 ==(0(1)6)'產生的邊緣iv1嗎?這很明顯,爲什麼它會出現錯誤,但目標不明確,因此解決方案無法實現。 –

+0

我正在嘗試創建一個邊際效應圖;所以下一個命令將是'marginsplot'。 – neutral

+0

爲什麼在(iv2 =(0(1)6))下的邊距dydx(iv1)不符合你的目的? –

回答

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 
------------------------------------------------------------------------------ 
+0

它表示文件不是Stata格式。 – neutral

+0

含義是你沒有使用Stata 13.所以,請詳細說明你正在使用的是什麼。 –

+0

我正在使用Stata 12. – neutral