Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: graph interaction in count models

From   Rodolphe Desbordes <>
To   "''" <>
Subject   st: RE: graph interaction in count models
Date   Thu, 1 Apr 2010 11:31:05 +0100

Dear Dali,

Another possibility, inspired by the Stata code which can be found here,  may be

webuse nlswork, clear
 xtset idcode year
 gen black = race == 2 if inlist(race, 1, 2)

xtgee wks_work c.tenure##c.grade south black, ///
      family(nb) link(log)

sum south
local south=r(mean)
sum black
local black=r(mean)
sum grade
local grade=r(mean)

set seed 12345
drawnorm b1-b6, n(10000) means(e(b)) cov(e(V)) clear

postutil clear
postfile mypost diff_hat diff_lo diff_hi   using sim , replace
            noisily display "start"

local a=0

while `a' <= 20 {


    generate pred0 =exp( b1*(`a')+b2*(`grade')+b3*`grade'*`a'+b4*`south'+b5*`black'+b6)

     generate pred1 =exp( b1*(`a')+b2*(`grade'+1)+b3*(`grade'+1)*`a'+b4*`south'+b5*`black'+b6)

gen diff=(pred1-pred0)

    egen diffhat=mean(diff)

    tempname  diff_hat diff_lo diff_hi

_pctile diff, p(2.5,97.5)
    scalar `diff_lo'= r(r1)
    scalar `diff_hi'= r(r2)
    scalar `diff_hat'=diffhat

    post mypost     (`diff_hat') (`diff_lo') (`diff_hi')
    drop pred0 pred1 diff  diffhat
    local a=`a'+1
    display "." _c

display ""

postclose mypost

use sim, clear

gen tenure=0 in 1

qui forval num= 2/20{
replace tenure = tenure[_n-1]+1 in `num'

twoway (line diff_hat tenure, sort lcolor(black) lwidth(thick) ytitle(Effect of a 1pt increase in current grade completed)) (line diff_lo tenure, sort lcolor(black) lwidth(thin) lpattern(dash)) (line diff_hi tenure, sort lcolor(black) lwidth(thin) lpattern(dash))



-----Original Message-----
From: [] On Behalf Of D Ma
Sent: mercredi 31 mars 2010 20:06
Subject: st: graph interaction in count models

Dear Colleagues,

I am trying to graph an interaction between two continuous covariates in a count model (xtgee y x1 x2 x1*x2 ..., family(nb) link(log) vce(robust) nolog).  Do you have any suggestions as to how draw such a graph?  Thanks!


*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index