Announcement

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

  • Passing graph names to macro

    Colleagues,

    I'm generating a number of strip plots using the code below. The idea is that indicators defined in dotinds will be often changed. How can automatically pass the names of generated graph to the combine command in order to create one graph with all strip plots.

    Code:
    // Define indicators to graph
    local dotinds    trunk weight price mpg rep78 headroom
    
    // Generate dot plots for some indicators
    foreach var of varlist `dotinds' {
        stripplot `var', name(plot_`var')
        }
    Kind regards,
    Konrad
    Version: Stata/IC 13.1

  • #2
    Just as with any other type of graph, I guess:
    Code:
    clear all
    sysuse auto
    // Define indicators to graph
    local dotinds    trunk weight price mpg rep78 headroom
    
    local plots ""
    // Generate dot plots for some indicators
    foreach var of varlist `dotinds' {
        graph pie `var', name(plot_`var') over(foreign)
        local plots `"`plots' plot_`var'"'
    }
    
    graph combine `plots', rows(2)
    graph drop `plots'
    Best, Sergiy Radyakin

    Click image for larger version

Name:	six_graphs.png
Views:	1
Size:	52.3 KB
ID:	47558

    Comment


    • #3
      Sergiy,

      Thank for your input. The last part wasn't obvious to me. Can I also make use of the opportunity and ask two more questions:
      1. How can I add ticks to x-axis?
      2. How can I define style for one dot depending on the string value of some other variable, I presume I will have to make use of the addplot function, is that correct?
      Kind regards,
      Konrad
      Version: Stata/IC 13.1

      Comment


      • #4
        Konrad,
        • Statalist recommends describing the source of everything non-standard to Stata, which is stripplot, which I don't have installed, but assume it's rational behavior as a Stata graph. That was enough to answer your initial question.
        • There are imho some good reasons to post new questions to new threads: someone who didn't know the answer to your initial question might ignore the updates to this thread (even though (s)he knows the answers to subsequent questions).

        Regarding the ticks, download my "Advanced Graphics Programming in Stata" presentation, and proceed to the Australian site (2nd link on the 5th slide ). Their gallery contains a stripplot illustration with x-labels and the corresponding syntax.

        Among my commands that never made it out yet there rests namechart, which I have written a while ago completely independently from stripplot. Note, that I have written namechart program for my own needs and it may or may not serve your's. You can net install from "http://www.radyakin.org/stata/namechart/"
        There is no documentation, but there are two examples. First example is for plotting events data:


        Second example is for contrasting two groups (here foreign vs. domestic cars, based on their headroom, which is very important! )


        I hope the program can be useful for the community. In your case, do you have more than two style groups or exactly two style groups?

        Best, Sergiy Radyakin

        Comment


        • #5
          As Sergiy underlines, stripplot is user-written and so you are asked to explain where it comes from, in this case SSC.

          Given two questions
          1. How can I add ticks to x-axis?
          2. How can I define style for one dot depending on the string value of some other variable, I presume I will have to make use of the addplot function, is that correct?
          If these are questions about stripplot, then I don't understand #1 as ticks appear on the x-axis by default for the way that Konrad is using the program.

          On #2, the answer is No. The addplot option (not a function) is not needed for this. The answer should be one of over(), by() or separate().

          Note also that you can call stripplot to show several variables, which will be often give a much better result than using graph combine.

          Comment


          • #6
            Thank you both for useful input, I'm almost there.
            Kind regards,
            Konrad
            Version: Stata/IC 13.1

            Comment

            Working...
            X