Bookmark and Share

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


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

st: RE: graph interaction in count models


From   Rodolphe Desbordes <[email protected]>
To   "'[email protected]'" <[email protected]>
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 http://homepages.nyu.edu/~mrg217/interaction.html,  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)

preserve
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))
restore

***

Rodolphe

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of D Ma
Sent: mercredi 31 mars 2010 20:06
To: [email protected]
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!

Dali





*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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