Announcement

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

  • crossplot available on SSC

    Thanks to Kit Baum, a program crossplot is downloadable from SSC. To install, use ssc as usual. Stata 8 is required. People on versions of Stata before 11 will need to copy the .sthlp file to .hlp.

    crossplot produces an array of scatter or other twoway plots for a yvarlist and an xvarlist. There is one plot for each y variable from yvarlist and each x variable from xvarlist. The name crossplot is intended to signal cross-combination. Graphs are drawn individually and then combined with graph combine.

    Note that only exceptionally is this similar to what graph matrix does. One y versus several x, several y versus several x, several y versus one x are all supported.

    The natural reaction of experienced Stata users to wanting an array of similar plots for differing variables is to write a loop, or two. But at the same time a convenience wrapper has some attractions. One of the motives for writing crossplot was definitely to support teaching, particularly for groups to whom the whole idea of programming a loop is usually neither obvious nor appealing.

    crossplot is in a strong sense just a reissue of cpyxplot, on SSC since 1999 or so. But I think the new name is better, the new syntax is better and crossplot has an extra detail that could be useful.

    There is a risk that a nice name, which I scrupulously avoided originally, is one that might taken by StataCorp for some purpose, but I will take that risk.

    More comments in the help.

    Here is a simple example:

    Code:
    sysuse auto, clear
    set scheme s1color
    gen rt_mpg = sqrt(mpg)
    gen ln_mpg = ln(mpg)
    gen rec_mpg = 100/mpg
    crossplot (mpg rt_mpg ln_mpg rec_mpg) weight, combine(imargin(small))

    Attached Files

  • #2
    Dear Nick

    I am curious to know about the advantage of the crossplot over the "graphmatrix" stata command??. Obviously this plot was designed for a purpose but I am not able to pick it up. Can you please explain.

    Also while you are writing code(or complicated code - for my standards) for plots such as "(h)bar plots with ranges, colors and extra information (label) on the right" could you please explain the rationale for key steps, so that readers can understand/follow along.

    Thanks
    Anwar

    Comment


    • #3
      I've already explained the key difference, so I don't know what is unclear to you. But let me put this the other way round. How you would get the display shown with graph matrix? If you specify 5 variables, you get 5 x 4 scatter plots, and at most you can suppress some of them by getting a half matrix. WIth crossplot you get to choose exactly which variables you want as y axis variables and x axis variables.

      Also, graph matrix does not have scope for twoway plots other than scatter.

      On commentary: I think I have a good track record at explaining graph code, but sometimes the time and the inclination to explain everything are not there.

      Comment


      • #4
        Hi Nick, this is extremely useful to quickly compare relationships and variabilities. I was wondering if there is anyway that you can combine graph types here. For example, in the example you show, is there a way to include a fitted line in all the scatterplots? Because this could quickly be useful to compare not just the dispersion, but also the fitted slopes of different subsamples.

        Thanks for the command!!!
        Alfonso Sanchez-Penalver

        Comment


        • #5
          Thanks. Short answer is No. I wanted to keep it very simple, not to try to create a way to get any possible portfolio of twoway plots. The coding for what you want is simple, just not part of crossplot.

          Comment


          • #6
            An afterthought on Alfonso's question:

            There is an ancient command of mine called cpr on SSC (1999 for Stata 6.0). That lets you write one-liners like this. You don't type the lines starting with arrows. Those are echoes of what Stata does.

            Code:
            . sysuse auto, clear
            (1978 Automobile Data)
            
            . cpr mpg price length \ weight : scatter @1 @2 || lfit @1 @2 , name(@1)
            
            -> scatter mpg weight || lfit mpg weight , name(mpg)
            
            -> scatter price weight || lfit price weight , name(price)
            
            -> scatter length weight || lfit length weight , name(length)
            You get a portfolio of graphs rather than a combined graph.

            I don't make any claims for this. It preceded foreach and was largely superseded by it. It's amusing that it still works.

            Comment


            • #7
              Originally posted by Nick Cox View Post
              An afterthought on Alfonso's question:

              There is an ancient command of mine called cpr on SSC (1999 for Stata 6.0). That lets you write one-liners like this. You don't type the lines starting with arrows. Those are echoes of what Stata does.

              <snip>

              I don't make any claims for this. It preceded foreach and was largely superseded by it. It's amusing that it still works.
              I tried your code. Unfortunately, however, I receive the error r(100). The following is a snippet from the output using set tracedepth 1 and set trace on:
              Code:
              = Doit mpg weight   
              -> scatter mpg weight || lfit mpg weight , name(mpg)
              { required
                local m = `m' + 1
                }
              Of course, I read that you don't make any claims. But it seems that it does not work (anymore) as intended.

              Comment


              • #8
                I do claim that what I did worked for me. I've not looked at the code since 1999, but I've no reason to suppose any difference between Stata 10.1 (on which I tested this) and whatever you are using should make it stop working. I'll not be able to explore further for a few days, but will get back to this.

                Comment


                • #9
                  Just got back to this. I can confirm Dirk's report that cpr (SSC) is broken by some internal change in Stata between 10.1 and 13.1.

                  In partial compensation I've been working on a new program with nicer syntax called combineplot. I hope to release this next week. As a taster

                  Code:
                   
                  combineplot mpg length weight displacement (price) : scatter @y @x || lfit @y @x
                  would give you one graph with four panels, each like scatter mpg price || lfit mpg price

                  Comment


                  • #10
                    This is just to report that, thanks to Kit Baum, crossplot has been updated on SSC. The update chiefly concerns extensions to the help file, including (1) more discussion and some references and (2) making documented two options that were previously undocumented.

                    The perhaps bigger news is that combineplot is also now public on SSC. I'll start a new thread on that, but I'll just note that the taster syntax given in the previous posting does not work as stated, due to changes while I was developing the program. The appropriate syntax would be

                    Code:
                      
                     combineplot (mpg length weight displacement) price : scatter @y @x || lfit @y @x

                    Comment

                    Working...
                    X