Hi,
I am trying to plot the interaction of a categorical variable with two other variables that have a quadratic effect on the dependent variable.
In my mind, that would give me two beautiful parabolas.
I am trying to adapt the code in for graph3d, with no success (found here: http://davud.rostam-afschar.de/graph...inb_example.do)
Ideas are welcome!
See a mock example:
I am trying to plot the interaction of a categorical variable with two other variables that have a quadratic effect on the dependent variable.
In my mind, that would give me two beautiful parabolas.
I am trying to adapt the code in for graph3d, with no success (found here: http://davud.rostam-afschar.de/graph...inb_example.do)
Ideas are welcome!
See a mock example:
Code:
* http://davud.rostam-afschar.de/graph3d/graph3d_zinb_example.do set more off /* load data */ clear sysuse auto /* estimate model: CHANGE MODEL HERE */ reg price i.foreign##c.mpg##c.mpg i.foreign##c.length##c.length /* specify values of x and y at which margins are calculated: CHANGE VALUES HERE */ local xfrom 15 local xto 40 local xstep 5 local yfrom 140 local yto 230 local ystep 10 /* post margins in matrix e(b) at specified values of the x and y variables: CHANGE VARIABLE FOR MARGINAL EFFECT HERE */ margins i.foreign, at(mpg=(`xfrom'(`xstep')`xto') length=(`yfrom'(`ystep')`yto')) post /* construct variable z */ mat b = e(b) mat mgns = b[1...,1...]' svmat double mgns, name(mgn) ren mgn1 z replace z=z*10 /* scale z variable to make it more visible: CHANGE SCALING HERE */ /* construct variables x and y */ gen x = . gen y = . forv lx = `xfrom'(`xstep')`xto' { forv ly = `yfrom'(`ystep')`yto' { replace x = `lx' in `=int((`ly'-`yfrom')/`ystep'+1+((`yto'-`yfrom')/`ystep'+1)*((`lx'-`xfrom')/`xstep'))' replace y = `ly' in `=int((`ly'-`yfrom')/`ystep'+1+((`yto'-`yfrom')/`ystep'+1)*((`lx'-`xfrom')/`xstep'))' } } /* plot variables x, y, and z: CHANGE OPTIONS HERE */ graph3d x y z, xangle(88) yangle(179) zangle(45) xcam(-30) zcam(200) mark cuboid innergrid blv perspective colorscheme(bcgyr) xlang(90) ylang(30) zlang(-12) xlpos(9) ylpos(4) zlpos(12) *graph export "car_prices.eps", replace
Comment