/* ***************************************************************** * * ******************************************************************* * File-Name: multiple predictions.do * Date: Janurary 21, 2015 * Author: Travis Braidwood, Texas A&M University--Kingsville * travis.braidwood@tamuk.edu * Purpose: Generating marginal effect plots using CLARIFY and user-written CLEAR-PLOT with multiple outcomes * Input File: n/a.dta, web access required * Data Output: None * Prev. file: None * Accompanying file: simqi.ado **Note: see below * Machine: Home * **************************************************************** * * **************************************************************** */ **************************************************************************** /* A note to users PRIOR to use: 1) You must set the seed to a given value if you wish to later replicate the same results. Below the seed of 0210 is given, but any value may be selected. 2) You must have installed the simqi.ado modification featured on Braidwood's website < http://travisbraidwood.altervista.org/dataverse.html > */ **************************************************************************** ********************************************************** * After the data is loaded we can start the program * ********************************************************** *EXAMPLE with a basic regression model* clear all set seed 0210 set scheme s2mono set more off, perm *example variables* webuse highschool, clear *correct values: 0 to = female, 1 male* replace sex =0 if sex ==2 *correct values: 1 white, 0 other replace race = 0 if race ==2 replace race = 0 if race ==3 *Model 1: weight = height + sex + race + (height*sex), a simple regression model with an dummy interaction gen xz = height*sex sum height sex race xz estsimp reg weight height sex race xz //clarify preserve setx mean //first set all to means, then modifiy where needed (below) local a = 355.1282 /* the minimum value */ local b = 1 /* males */ local c = `a'*`b' setx height (`a') sex (`b') xz (`c') race 1 /* white males over a range of height values */ simqi postutil clear postfile mypost probY upper lower xaxis using simresults, replace noisily display "start" set obs 10000 //this may need to be dropped if you have many observations while `a' <= 512.82 /* which is the max */ { qui simqi scalar probY= Pr scalar upper = PrU scalar lower = PrL scalar xaxis = `a' post mypost (probY) (upper) (lower) (xaxis) scalar drop probY upper lower local a = `a'+1 //the amount we will increase height by local b = 1 //redundant here, but might be needed in other instances local c = `a'*`b' setx height (`a') xz (`c') //keeping race and gender constant at 1 local xaxis = `a' //move across the xaxis by a units display "." _c } display "" postclose mypost merge using simresults //merge in the results to our dataset gsort probY upper lower -xaxis ************************************************************************************ * Model 2: weight = height + height^2 + sex + race, a simple regression model w/o interaction * ************************************************************************************ * drop _merge //we need to drop this, since we have two files capture { fored break //this is included to force the .do file to break } *still using "estsimp reg weight height sex race xz" from before setx mean //first set all to means, then modifiy where needed (below) local a = 355.1282 /* the minimum value */ local b = 0 /* females--we changed this */ local c = (`a')*(`b') setx height (`a') sex (`b') race 1 xz (`c') //others are still at their means * simqi postutil clear postfile mypost2 probY2 upper2 lower2 using simresults2, replace noisily display "start" set obs 10000 * while `a' <= 512.8205 /* which is the max height */ { qui simqi scalar probY2= Pr scalar upper2 = PrU scalar lower2 = PrL post mypost2 (probY2) (upper2) (lower2) scalar drop probY2 upper2 lower2 local a = `a'+1 //the amount we will increase height by local b = 0 //redundant here, but might be needed in other instances local c = `a'*`b' setx height (`a') xz (`c') display "." _c } display "" postclose mypost2 /* now we have the numbers we need, so close the post */ merge using simresults2 graph twoway line probY xaxis, clwidth(.5) clcolor(black) clpattern(solid) /// || line lower xaxis, clpattern(dash) clwidth(medium) clcolor(navy) /// || line upper xaxis, clpattern(dash) clwidth(medium) clcolor(navy) /// || line probY2 xaxis, clpattern(solid) clwidth(.5) clcolor(black) /// || line upper2 xaxis, clpattern(dash) clwidth(medium) clcolor(red) /// || line lower2 xaxis, clpattern(dash) clwidth(medium) clcolor(red)