Announcement

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

  • How can I get gr_edit to refer to specific graphs when multiple graphs are open in the graph window?

    I'm using a user-created command (-synth2-) that generates multiple graphs as outputs. I want to be able to edit these graphs with code, but there doesn't seem to be an easy way to do this with the synth2 command. Thus, I am instead trying to use the -gr_edit- command.

    However, I'm running into a problem where the -gr_edit- command only applies changes to the last graph generated by the synth2 command. I don't know how to get gr_edit to refer to a specific graph.

    To demonstrate my issue, consider the following example. Suppose I generate a scatterplot (graph1) and a histogram (graph2).
    Code:
    sysuse auto, clear
    scatter price mpg, name(graph1)
    histogram price, name(graph2)
    Suppose I want to use gr_edit to make the scatterplot markers orange and the histogram bars blue. How would I do this?

    My attempt was:
    Code:
    gr_edit plotregion1.plot1.style.editstyle marker(fillcolor(orange)) editcopy
    gr_edit plotregion1.plot1.style.editstyle marker(linestyle(color(orange))) editcopy
    
    gr_edit plotregion1.plot1.style.editstyle area(shadestyle(color(blue))) editcopy
    Since I don't know how to get gr_edit to refer to specific graphs (e.g. "graph1" vs. "graph2"), this command just made the histogram bars blue and didn't do anything to the scatterplot markers.

  • #2
    As (probably) the main expert on SCM on this forum, may I make a suggestion to you?

    Comment


    • #3
      Code:
      graph display graph1
      gr_edit plotregion1.plot1.style.editstyle marker(fillcolor(orange)) editcopy
      gr_edit plotregion1.plot1.style.editstyle marker(linestyle(color(orange))) editcopy
      
      graph display graph2
      gr_edit plotregion1.plot1.style.editstyle area(shadestyle(color(blue))) editcopy

      Comment


      • #4
        @William - Thanks!

        @Jared - Yes, that'd be appreciated!

        Comment


        • #5
          Wait, before I give a recommendation, I want details on what precisely you want, nothing abstract, yes? So, please run this code
          Code:
          clear *
          
          u "http://fmwww.bc.edu/repec/bocode/s/scul_basque.dta", clear
          
          qui xtset
          local lbl: value label `r(panelvar)'
          
          loc unit ="Basque Country (Pais Vasco)":`lbl'
          
          loc colax white
          
          
          loc int_time = 1975
          
          qui xtset
          cls
          
          g treat = cond(`r(panelvar)'==`unit' & `r(timevar)' >= `int_time',1,0)
          
          loc x 1961(1)1969
          
          loc y 1960(1)1969
          
          loc z 1964(1)1969
          
          
          
          tempfile scmbasque scmbasque2
          cls
          synth2 gdpcap /// classic SCM- Justin Wiltshire's command
              gdpcap(`y') ///
              pop(1969) ///
                  sec_agriculture(`x') ///
                  sec_energy(`x') ///
                  sec_industry(`x') ///
                  sec_construction(`x') ///
                  sec_svc_venta(`x') ///
                  sec_svc_nonventa(`x') ///
              school_illit(`z') ///
              school_prim(`z') ///
              school_med(`z') ///
              school_high(`z') ///
              invest(`z'), ///
              trunit(5) ///
              trperiod(`int_time') ///
              allopt nested fig frame(basqueex)
          And tell me what exactly you'd like to edit? gr_edit works here, but it's a little like using a quantum microscope to see an ant. You can use it, but it's likely more involved than you'd like to do what you want. Noah Spencer

          Comment


          • #6
            For weight_unit.gph, I'd like to remove the title and change the x-axis title to "Weight".

            For pred.gph, I would remove the title, change the y-axis title to "GDP per capita", change the x-axis title to "Year", change the legend text to "Basque" and "Synthetic Basque".

            For eff.gph, I would remove the title, change the y-axis title to "Gap in GDP per capita between Basque and Synthetic Basque", and change the x-axis title to "Year".

            Comment


            • #7
              Hey, so if this were my problem, here's what I'd do. You already have a dataframe that does what you'd like. Switching to this dataframe allows you MUCH more control than than gr_edit allows. I wish that the authors allowed you to have more control over this stuff, but that's not my job
              Code:
              clear *
              
              u "http://fmwww.bc.edu/repec/bocode/s/scul_basque.dta", clear
              
              qui xtset
              local lbl: value label `r(panelvar)'
              
              loc unit ="Basque Country (Pais Vasco)":`lbl'
              
              loc colax white
              
              
              loc int_time = 1975
              
              qui xtset
              cls
              
              g treat = cond(`r(panelvar)'==`unit' & `r(timevar)' >= `int_time',1,0)
              
              loc x 1961(1)1969
              
              loc y 1960(1)1969
              
              loc z 1964(1)1969
              
              
              
              tempfile scmbasque scmbasque2
              cls
              synth2 gdpcap /// classic SCM- Justin Wiltshire's command
                  gdpcap(`y') ///
                  pop(1969) ///
                      sec_agriculture(`x') ///
                      sec_energy(`x') ///
                      sec_industry(`x') ///
                      sec_construction(`x') ///
                      sec_svc_venta(`x') ///
                      sec_svc_nonventa(`x') ///
                  school_illit(`z') ///
                  school_prim(`z') ///
                  school_med(`z') ///
                  school_high(`z') ///
                  invest(`z'), ///
                  trunit(5) ///
                  trperiod(`int_time') ///
                  allopt nested fig frame(basqueex)
                  
                  frame change basqueex
                  
              keep if id ==5
              
                  
              keep id year gdpcap pred·gdpcap tr·gdpcap
              
              cls
              twoway (tsline gdpcap, lcolor(black) lwidth(medthick) lpattern(solid)) ///
              (tsline pred·gdpcap, lcolor(green) lwidth(medium) lpattern(shortdash)), ///
                  ytitle(GDP per Capita) ///
                  ttitle(Year) ///
                  legend(order(1 "Basque" 2 "Synthetic Basque") ///
                  region(fcolor(none)) ///
                  position(5) ///
                  ring(0)) tli(1975, lpat(dash) lcol(black)) name(obspred, replace)
                  
                  
              g diff = gdpcap - pred
              
              twoway (tsline diff, lcolor(black) lwidth(medthick) lpattern(solid)), ///
                  yti(Gap Between Basque and Synthetic Basque) tti(Year) ///
                  yli(0, lwid(vthin) lcol(black)) name(diff, replace)
                  
              preserve
              svmat matout
              keep if matout != 0
              drop if matout == .
              graph bar (mean) matout1 (mean) matout1, over(year, relabel(1 "Cataluna" 2 "Madrid")) ///
              yti(Weight) name(Weights, replace)
              restore
              There is a more eloquent way to do some of this, like you could use the user written coefplot to do the weights graph. but to me, this is you best bet which gives you the highest amount of functionality. If you don't mind me asking, what's your research question, what're we evaluating here? Noah Spencer

              Comment


              • #8
                Thanks Jared - I'll give this a try! I'm evaluating the impact of a state-level policy change on the mortality rate in that state.

                Comment


                • #9
                  Can you give me more details? Which state? How many donors are there, what's your time period, how many pre-intervention periods we talking about?

                  Comment

                  Working...
                  X