I have an individual-by-week panel for 52 weeks. I want to examine the effect of a variable 'tot' on probability of death. My data looks as follows:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long case_number byte week float(death tot male) byte(race age1639 age40plus eduhs edulcol educol edupg edumiss) float(ever_op ever_od ever_booked ever_total_ed) 100064 1 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 2 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 3 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 4 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 5 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 6 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 7 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 8 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 9 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 10 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 11 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 12 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 13 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 14 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 15 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 16 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 17 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 18 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 19 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 20 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 21 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 22 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 23 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 24 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 25 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 26 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 27 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 28 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 29 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 30 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 31 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 32 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 33 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 34 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 35 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 36 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 37 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 38 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 39 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 40 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 41 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 42 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 43 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 44 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 45 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 46 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 47 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 48 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 49 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 50 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 51 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100064 52 1 0 1 1 1 0 1 0 0 0 0 0 0 0 0 100076 1 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 2 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 3 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 4 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 5 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 6 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 7 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 8 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 9 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 10 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 11 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 12 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 13 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 14 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 15 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 16 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 17 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 18 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 19 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 20 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 21 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 22 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 23 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 24 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 25 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 26 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 27 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 28 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 29 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 30 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 31 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 32 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 33 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 34 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 35 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 36 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 37 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 38 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 39 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 40 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 41 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 42 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 43 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 44 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 45 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 46 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 47 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 100076 48 0 0 1 2 0 1 1 0 0 0 0 0 0 0 0 end
My key independent variable 'tot' ranges from 0-38, however its skewed.
Code:
. tab tot, miss tot | Freq. Percent Cum. ------------+----------------------------------- 0 | 82,690 68.45 68.45 1 | 18,441 15.27 83.72 2 | 8,355 6.92 90.64 3 | 4,211 3.49 94.12 4 | 2,360 1.95 96.08 5 | 1,493 1.24 97.31 6 | 899 0.74 98.06 7 | 644 0.53 98.59 8 | 477 0.39 98.99 9 | 200 0.17 99.15 10 | 183 0.15 99.30 11 | 140 0.12 99.42 12 | 126 0.10 99.52 13 | 125 0.10 99.63 14 | 90 0.07 99.70 15 | 74 0.06 99.76 16 | 111 0.09 99.85 17 | 27 0.02 99.88 18 | 29 0.02 99.90 19 | 28 0.02 99.92 20 | 45 0.04 99.96 21 | 10 0.01 99.97 22 | 6 0.00 99.97 23 | 11 0.01 99.98 24 | 3 0.00 99.99 25 | 1 0.00 99.99 26 | 1 0.00 99.99 27 | 1 0.00 99.99 28 | 1 0.00 99.99 29 | 1 0.00 99.99 30 | 1 0.00 99.99 31 | 1 0.00 99.99 32 | 2 0.00 99.99 33 | 1 0.00 99.99 34 | 2 0.00 100.00 35 | 1 0.00 100.00 36 | 3 0.00 100.00 37 | 1 0.00 100.00 38 | 1 0.00 100.00 ------------+----------------------------------- Total | 120,796 100.00
Code:
. logit death tot $covariates c.yw, or vce(cluster case_number) Iteration 0: log pseudolikelihood = -11479.258 Iteration 1: log pseudolikelihood = -11214.26 Iteration 2: log pseudolikelihood = -11183.852 Iteration 3: log pseudolikelihood = -11183.824 Iteration 4: log pseudolikelihood = -11183.824 Logistic regression Number of obs = 120,796 Wald chi2(11) = 727.94 Prob > chi2 = 0.0000 Log pseudolikelihood = -11183.824 Pseudo R2 = 0.0257 (Std. Err. adjusted for 2,323 clusters in case_number) ------------------------------------------------------------------------------ | Robust death | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- tot | 1.16571 .017594 10.16 0.000 1.131731 1.200708 male | 1.071387 .0338684 2.18 0.029 1.007021 1.139868 | race | 2 | .9537488 .033283 -1.36 0.175 .8906962 1.021265 3 | 1.081874 .0478604 1.78 0.075 .9920214 1.179866 4 | .9813072 .0397271 -0.47 0.641 .9064525 1.062343 | age1639 | 1.005282 .0269937 0.20 0.844 .9537432 1.059605 eduhs | .9189303 .0226669 -3.43 0.001 .8755607 .9644481 educol | 1.107214 .0361908 3.12 0.002 1.038505 1.180467 edupg | 1.143021 .1018002 1.50 0.133 .9599403 1.36102 edumiss | .8451781 .0305153 -4.66 0.000 .7874363 .907154 yw | 1.001862 .0001051 17.74 0.000 1.001656 1.002068 _cons | .0000819 .0000232 -33.27 0.000 .0000471 .0001426 ------------------------------------------------------------------------------ Note: _cons estimates baseline odds.
OPTION 1: Monotonically increasing.
Code:
margins, dydx(tot) at(tot=(0(2)38)) Average marginal effects Number of obs = 120,796 Model VCE : Robust Expression : Pr(death), predict() dy/dx w.r.t. : tot 1._at : tot = 0 2._at : tot = 2 3._at : tot = 4 4._at : tot = 6 5._at : tot = 8 6._at : tot = 10 7._at : tot = 12 8._at : tot = 14 9._at : tot = 16 10._at : tot = 18 11._at : tot = 20 12._at : tot = 22 13._at : tot = 24 14._at : tot = 26 15._at : tot = 28 16._at : tot = 30 17._at : tot = 32 18._at : tot = 34 19._at : tot = 36 20._at : tot = 38 ------------------------------------------------------------------------------ | Delta-method | dy/dx Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- tot | _at | 1 | .002435 .0002032 11.98 0.000 .0020366 .0028333 2 | .0032689 .0003674 8.90 0.000 .0025489 .0039889 3 | .0043699 .0006137 7.12 0.000 .0031671 .0055727 4 | .0058089 .0009711 5.98 0.000 .0039056 .0077121 5 | .0076643 .0014711 5.21 0.000 .004781 .0105475 6 | .0100136 .0021417 4.68 0.000 .0058159 .0142113 7 | .0129175 .0029953 4.31 0.000 .0070468 .0187882 8 | .0163934 .0040091 4.09 0.000 .0085357 .0242512 9 | .0203815 .0051016 4.00 0.000 .0103826 .0303804 10 | .0247062 .0061126 4.04 0.000 .0127257 .0366866 11 | .0290524 .0068067 4.27 0.000 .0157116 .0423932 12 | .0329767 .006917 4.77 0.000 .0194196 .0465338 13 | .0359731 .0062361 5.77 0.000 .0237506 .0481955 14 | .03759 .0047208 7.96 0.000 .0283374 .0468427 15 | .037562 .0025534 14.71 0.000 .0325575 .0425665 16 | .0358954 .0001211 296.34 0.000 .035658 .0361329 17 | .0328661 .0022006 14.93 0.000 .0285529 .0371792 18 | .0289285 .0040057 7.22 0.000 .0210776 .0367795 19 | .0245856 .0051431 4.78 0.000 .0145053 .034666 20 | .0202747 .0056198 3.61 0.000 .00926 .0312893 ------------------------------------------------------------------------------ . marginsplot, recast(line) recastci(rarea) ciopt(lcolor(navy) fcolor(ebblue) color(%20)) plot1opts(lcolor(navy) fcolor(ebblue% > 35))
OPTION 2: Here the line is not monotonically increasing.
Code:
. margins, at(tot=(0(2)38)) post Predictive margins Number of obs = 120,796 Model VCE : Robust Expression : Pr(death), predict() 1._at : tot = 0 2._at : tot = 2 3._at : tot = 4 4._at : tot = 6 5._at : tot = 8 6._at : tot = 10 7._at : tot = 12 8._at : tot = 14 9._at : tot = 16 10._at : tot = 18 11._at : tot = 20 12._at : tot = 22 13._at : tot = 24 14._at : tot = 26 15._at : tot = 28 16._at : tot = 30 17._at : tot = 32 18._at : tot = 34 19._at : tot = 36 20._at : tot = 38 ------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- _at | 1 | .0161552 .0002804 57.61 0.000 .0156055 .0167048 2 | .0218199 .0003474 62.81 0.000 .021139 .0225007 3 | .0294085 .0012881 22.83 0.000 .0268839 .0319331 4 | .0395245 .0028461 13.89 0.000 .0339462 .0451028 5 | .0529216 .0052592 10.06 0.000 .0426138 .0632294 6 | .0705113 .00884 7.98 0.000 .0531851 .0878374 7 | .0933467 .0139457 6.69 0.000 .0660136 .1206798 8 | .1225643 .020927 5.86 0.000 .0815481 .1635805 9 | .1592645 .0300344 5.30 0.000 .1003981 .2181308 10 | .2043179 .0412789 4.95 0.000 .1234126 .2852231 11 | .2581065 .0542725 4.76 0.000 .1517342 .3644787 12 | .3202477 .0681134 4.70 0.000 .1867479 .4537475 13 | .3893935 .0814074 4.78 0.000 .229838 .548949 14 | .4632161 .0924939 5.01 0.000 .2819313 .6445009 15 | .5386507 .0998485 5.39 0.000 .3429511 .7343502 16 | .6123655 .1025131 5.97 0.000 .4114435 .8132875 17 | .6813198 .1003565 6.79 0.000 .4846246 .878015 18 | .7432234 .0940483 7.90 0.000 .5588921 .9275546 19 | .7967653 .0847843 9.40 0.000 .6305911 .9629395 20 | .8415902 .0739196 11.39 0.000 .6967105 .9864699 ------------------------------------------------------------------------------ . marginsplot, recast(line) recastci(rarea) ciopt(lcolor(navy) fcolor(ebblue) color(%20)) plot1opts(lcolor(navy) fcolor(ebblue% > 35))
Many thanks for your help.
Sumedha.
0 Response to margins and marginsplot after logit.
Post a Comment