I've been running graphs and was trying to use grc1leg to combine graphs so I only have one heading but I keep getting an error that says:
"final.graphs[2].legend.draw_view.set_false: class type not found"
The only thing I can think of is I switched to try and do it with graph combine yesterday and ran:
as suggested in another form (I couldn't get it to work so I was going to go back to grc1leg). Stata has been closed and my computer has been rebooted since then though so I wouldn't think it would stick in the memory? g1c1leg was working yesterday fine (some of my coding has changed since then so it is possible I have something messing with it).
What I'm trying to do is run 2 graphs of Predictive Margins (One full scale one zoomed in) and combine those two together and save it, and 2 graphs of percentage change (one full scale one zoomed in) and combine those two together a and save it, and then combine the two combined graphs with one legend (the legend is the same for all of the graphs).
I can get up to trying to do the final combination. My full code is below (with the grc1leg code I'm trying to use which I have bolded).
I have also tried the code with the graph names themselves rather than the `x' (both in and outside of the macro) and I get the same error. If anyone knows what the issue might be, I would really appreciate the help. Thanks.
"final.graphs[2].legend.draw_view.set_false: class type not found"
The only thing I can think of is I switched to try and do it with graph combine yesterday and ran:
Code:
_gm_edit .leg.plotregion1.draw_view.set_false graph display _gm_edit .leg.ystretch.set fixed graph display
What I'm trying to do is run 2 graphs of Predictive Margins (One full scale one zoomed in) and combine those two together and save it, and 2 graphs of percentage change (one full scale one zoomed in) and combine those two together a and save it, and then combine the two combined graphs with one legend (the legend is the same for all of the graphs).
I can get up to trying to do the final combination. My full code is below (with the grc1leg code I'm trying to use which I have bolded).
I have also tried the code with the graph names themselves rather than the `x' (both in and outside of the macro) and I get the same error. If anyone knows what the issue might be, I would really appreciate the help. Thanks.
Code:
local yvar DRS_Score CHESS_Score PAIN_Score ADL_H_SCORE ADL_S_SCORE ADL_L_SCORE ISE_SCORE PSI_SCORE ABS_SCORE PURS_SCORE CPS_SCORE
local tvar 13 5 3 6 16 28 6 18 12 8 6
local zvar 3.5 1.5 1 4.5 11.5 19.5 4.5 6.5 4.5 3 4.5
local mvar 0 0 0 3 8 14 1 3.5 .5 1.5 2.5
local nvar Depression CHESS Pain ADL_H ADL_S ADL_L ISE PSI ABS PURS CPS
forval k = 1/11 {
local y : word `k' of `yvar'
local t : word `k' of `tvar'
local n : word `k' of `nvar'
local z : word `k' of `zvar'
local m : word `k' of `mvar'
display as result "Outcome = `y'"
anova `y' Sex_AA2 Pre_LTCH Sex_AA2#Pre_LTCH / ///
unique_ID|Pre_LTCH#Sex_AA2 ///
data_point ///
data_point#Sex_AA2 data_point#Pre_LTCH ///
data_point#Sex_AA2#Pre_LTCH ///
if Sex_AA2!=2, ///
rep(data_point)
margins, over(Pre_LTCH Sex_AA2 data_point) saving(`n', replace)
marginsplot, xdim(data_point) ylabel(0 `t') ytick(0(1)`t') name(`n',replace) ///
graphregion(margin(5 20 10 5)) graphregion(color(white)) bgcolor(white) title("Predictive Margins for `n'") ///
xtitle("Time point") ytitle("Adjusted Prediction (0-`t')")
marginsplot, xdim(data_point) ylabel(`m' `z') ytick(`m'(.5)`z') name(`n'zoom,replace) ///
graphregion(margin(5 20 10 5)) graphregion(color(white)) ///
bgcolor(white) title("Zoomed Predictive Margins for `n'") ///
xtitle("Time point") ytitle("Adjusted Prediction (0-`t')")
Graph combine `n' `n'zoom, cols(2) name(`n'both, replace) xsize(20) ysize(11) forcesize
graph close `n' `n'zoom
graph export "`n'.png", as(png) replace
}
local xvar Depression CHESS Pain ADL_H ADL_S ADL_L ISE PSI ABS PURS CPS
forval k = 1/11 {
local x : word `k' of `xvar'
use "`x'.dta", clear
gen subject=1 if _by1==1 & _by2==0
replace subject=2 if _by1==1 & _by2==1
replace subject=3 if _by1==2 & _by2==0
replace subject=4 if _by1==2 & _by2==1
replace subject=5 if _by1==3 & _by2==0
replace subject=6 if _by1==3 & _by2==1
label define Subject 1 "Dawson Male" 2 "Dawson Female" 3 "Grandview Male" 4 "Grandview Female" 5 "Old HRM Male" 6 "Old HRM Female"
label values subject Subject
generate marginchange = _margin[_n] - _margin[_n-1]
drop if _by3==1
replace _by3=1 if _by3==2
replace _by3=2 if _by3==3
replace _by3=3 if _by3==4
label define data 1 "1 and 2" 2 "2 and 3" 3 "3 and 4"
label values _by3 data
twoway (connected marginchange _by3 if subject==1, sort) (connected marginchange _by3 if subject==2, sort) ///
(connected marginchange _by3 if subject==3, sort) (connected marginchange _by3 if subject==4, sort) ///
(connected marginchange _by3 if subject==5, sort) (connected marginchange _by3 if subject==6, sort) ///
, name(`x'change1,replace) ytitle(Percentage Change) ylabel(-1(.5)1, labels valuelabel) ymtick(none) xtitle(Between Time Points) ///
xlabel(#3, labels valuelabel) title(% Change `x') graphregion(fcolor(white)) legend(order(1 "Dawson Male" 2 "Dawson Female" 3 "Grandview Male" 4 "Grandview Female" 5 "Old HRM Male" 6 "Old HRM Female"))
twoway (connected marginchange _by3 if subject==1, sort) (connected marginchange _by3 if subject==2, sort) ///
(connected marginchange _by3 if subject==3, sort) (connected marginchange _by3 if subject==4, sort) ///
(connected marginchange _by3 if subject==5, sort) (connected marginchange _by3 if subject==6, sort) ///
, name(`x'change2,replace) ytitle(% Change) xtitle(Between Time Points) ///
xlabel(#3, labels valuelabel) title(Zoomed in % Change `x') graphregion(fcolor(white)) legend(order(1 "Dawson Male" 2 "Dawson Female" 3 "Grandview Male" 4 "Grandview Female" 5 "Old HRM Male" 6 "Old HRM Female"))
graph combine `x'change1 `x'change2 , cols(2) name(`x'combo, replace)
graph export "`x'combo.png", as(png) replace
graph close `x'change1 `x'change2
grc1leg `x'combo `x'both, ///
altshrink name(`n'both, replace) ///
title("`n'", size(medium))
}

Comment