Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • grc1leg error

    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:

    Code:
    _gm_edit .leg.plotregion1.draw_view.set_false
    
    graph display
    
    _gm_edit .leg.ystretch.set fixed
    
    graph display
    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.


    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)) 
    }

  • #2
    I believe this is the grc1leg command Elyse is talking about:

    Code:
    net describe grc1leg, from(http://www.stata.com/users/vwiggins)
    --
    Bruce Weaver
    Email: [email protected]
    Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
    Version: Stata/MP 18.0 (Windows)

    Comment


    • #3
      I have never used -grc1leg-, but here are two things to check.
      1. One of your -graph combine- commands is written as -Graph combine-.
      2. In the final -grc1leg- command, you appear to be trying to combine two graphs called `x'combo and `x'both. When I search your code for <`x'both>, I only find one instance. Shouldn't there be some earlier code to generate (and name) that graph?
      HTH.
      --
      Bruce Weaver
      Email: [email protected]
      Web: http://sites.google.com/a/lakeheadu.ca/bweaver/
      Version: Stata/MP 18.0 (Windows)

      Comment


      • #4
        Hi Bruce, 'x'both is named in the first part (it's using an n variable but the n variables in the first part are the same as the x variables in the second part. I'm going to try and writing them both as the same variable and see if it makes a difference. (I'm running the macros separately so I didn't think it would.)


        Originally posted by Bruce Weaver View Post
        I have never used -grc1leg-, but here are two things to check.
        1. One of your -graph combine- commands is written as -Graph combine-.
        2. In the final -grc1leg- command, you appear to be trying to combine two graphs called `x'combo and `x'both. When I search your code for <`x'both>, I only find one instance. Shouldn't there be some earlier code to generate (and name) that graph?
        HTH.

        Comment


        • #5
          I fixed them but I'm still getting the error. I tried tracing the error and get the following message with the error code (I don't know enough about Stata to understand what it means though).

          I guess alternatively is there a way to use graph combine so that I have my four graphs with just one legend at the very bottom of the page (underneath and centered)?



          ---------------------------------------------------------------------------------------------------------------------------------------- begin _gm_edit ---
          - version 8
          - `0'
          = .Graph.graphs[1].legend.draw_view.set_false
          Graph.graphs[1].legend.draw_view.set_false: class type not found
          ------------------------------------------------------------------------------------------------------------------------------------------ end _gm_edit ---
          _gm_edit .`name'.graphs[`i'].legend.fill_if_undrawn.set_false
          }
          --------------------------------------------------------------------------------------------------------------------------------------------- end grc1leg ---




          The full tracing is:




          . set traced 2

          . set trace on

          . grc1leg PURScombo PURSboth
          ------------------------------------------------------------------------------------------------------------------------------------------- begin grc1leg ---
          - syntax [anything] [, LEGendfrom(string) POSition(string) RING(integer -1) SPAN NAME(passthru) SAVing(string asis) * ]
          - gr_setscheme , refscheme
          ------------------------------------------------------------------------------------------------------------------------------------ begin gr_setscheme ---
          - version 8
          - args scheme
          - syntax [ , SCHeme(string) COPYSCHeme REFSCHeme * ]
          - if "`copyscheme'`refscheme'" != "" {
          = if "refscheme" != "" {
          - if "`scheme'" == "" {
          = if "" == "" {
          - if "`.`c(curscm)'.scheme_name'" != "`c(scheme)'" {
          = if "s2color" != "s2color" {
          local newscheme 1
          }
          - else local scheme `c(curscm)'
          = else local scheme __key(272a9638)
          - }
          - else if "`.`scheme'.classname'" != "scheme" {
          = else if "scheme" != "scheme" {
          local newscheme 1
          }
          - if ! 0`newscheme' {
          = if ! 0 {
          - if "`refscheme'" != "" {
          = if "refscheme" != "" {
          - if "`.__SCHEME.objkey'" != "`.`scheme'.objkey'" {
          = if "__key(29283078)" != "__key(272a9638)" {
          - capture _cls free __SCHEME
          - .__SCHEME = .`scheme'.ref
          = .__SCHEME = .__key(272a9638).ref
          - }
          - }
          - else .__SCHEME = .`scheme'.copy
          = else .__SCHEME = .__key(272a9638).copy
          - }
          - }
          - else local newscheme 1
          - if 0`newscheme' {
          = if 0 {
          capture _cls free __SCHEME
          if "`scheme'" == "" {
          if "`c(scheme)'" == "" {
          local scheme s2color
          }
          else local scheme `c(scheme)'
          }
          .__SCHEME = .scheme.new, scheme(`scheme')
          }
          - set curscm `.__SCHEME.objkey'
          = set curscm __key(272a9638)
          -------------------------------------------------------------------------------------------------------------------------------------- end gr_setscheme ---
          - tempname clockpos
          - if ("`position'" == "") local position 6
          = if ("" == "") local position 6
          - .`clockpos' = .clockdir.new , style(`position')
          = .__000000 = .clockdir.new , style(6)
          ------------------------------------------------------------------------------------------------------------------------------ begin clockdir._unabbrev ---
          - version 8
          - local 0 , `0'
          = local 0 , 6
          - syntax [ , Center Top Bottom Left Right * ]
          - if "`center'`top'`bottom'`left'`right'" == "" {
          = if "" == "" {
          - class exit "`options'"
          = class exit "6"
          -------------------------------------------------------------------------------------------------------------------------------- end clockdir._unabbrev ---
          - local location `.`clockpos'.relative_position'
          ---------------------------------------------------------------------------------------------------------------------- begin clockdir.relative_position ---
          - version 8
          - if `.iseast' {
          = if 0 {
          class exit "rightof"
          }
          - if `.iswest' {
          = if 0 {
          class exit "leftof"
          }
          - if `.issouth' {
          = if 1 {
          - class exit "below"
          ------------------------------------------------------------------------------------------------------------------------ end clockdir.relative_position ---
          = local location below
          - if `ring' > -1 {
          = if -1 > -1 {
          if (`ring' == 0) {
          local location "on"
          local ring ""
          }
          else local ring "ring(`ring')"
          }
          - else local ring ""
          - if "`span'" != "" {
          = if "" != "" {
          if "`location'" == "above" | "`location'" == "below" {
          local span spancols(all)
          }
          else local span spanrows(all)
          }
          - if "`legendfrom'" != "" {
          = if "" != "" {
          local lfrom : list posof "`legendfrom'" in anything
          if `lfrom' == 0 {
          di as error `"`legend_from' not found in graph name list"'
          exit 198
          }
          }
          - else local lfrom 1
          - graph combine `anything' , `options' `name' nodraw
          = graph combine PURScombo PURSboth , nodraw
          ------------------------------------------------------------------------------------------------------------------------------------------- begin graph ---
          - if d(`=c(born_date)') < d(23Jul2004) {
          = if d(26 Aug 2019) < d(23Jul2004) {
          di as err "your Stata executable is out of date"
          di as err " type -update executable- at the Stata prompt"
          exit 498
          }
          - local ver = string(_caller())
          - if (_caller() < 8.2) version 8
          - else if (_caller() < 10 ) version 8.2
          - else version 10
          - gdi record = yes
          - gdi maybedraw = yes
          - if "`._Gr_Global.isa'" == "" {
          = if "class" == "" {
          ._Gr_Global = .global_g.new
          }
          - ._Gr_Global.callerver = "`ver'"
          = ._Gr_Global.callerver = "15.1"
          - capture noisily Graph `0'
          = capture noisily Graph combine PURScombo PURSboth , nodraw
          - local rc = _rc
          - gdi record = yes
          - gdi maybedraw = yes
          - gdi end
          - exit `rc'
          = exit 0
          --------------------------------------------------------------------------------------------------------------------------------------------- end graph ---
          - if "`name'" != "" {
          = if "" != "" {
          local 0 `", `name'"'
          syntax [, name(string) ]
          local 0 `"`name'"'
          syntax [anything(name=name)] [, replace]
          }
          - else local name Graph
          - forvalues i = 1/`:list sizeof anything' {
          = forvalues i = 1/2 {
          - _gm_edit .`name'.graphs[`i'].legend.draw_view.set_false
          = _gm_edit .Graph.graphs[1].legend.draw_view.set_false
          ---------------------------------------------------------------------------------------------------------------------------------------- begin _gm_edit ---
          - version 8
          - `0'
          = .Graph.graphs[1].legend.draw_view.set_false
          Graph.graphs[1].legend.draw_view.set_false: class type not found
          ------------------------------------------------------------------------------------------------------------------------------------------ end _gm_edit ---
          _gm_edit .`name'.graphs[`i'].legend.fill_if_undrawn.set_false
          }
          --------------------------------------------------------------------------------------------------------------------------------------------- end grc1leg ---
          r(4018);





          Originally posted by Bruce Weaver View Post
          I have never used -grc1leg-, but here are two things to check.
          1. One of your -graph combine- commands is written as -Graph combine-.
          2. In the final -grc1leg- command, you appear to be trying to combine two graphs called `x'combo and `x'both. When I search your code for <`x'both>, I only find one instance. Shouldn't there be some earlier code to generate (and name) that graph?
          HTH.

          Comment


          • #6
            Elyse, have you solved this problem? If not, you might want to try working through the help file for my hacked version of -grc1leg-. To find my version and work through its help file, execute "search grc1leg2" from inside Stata.

            Comment

            Working...
            X