Announcement

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

  • Add sample size to scatter plot

    I'm using the command "scatter", and I need to produce several scatterplots. Each of these considers a different subsample of my observations, and I need to include the number of observations in each scatterplot.

    Is there an easy way to do so, and have the sample size directly appear in the output graph? I tried looking at the syntax for "scatter" but I couldn't see any command or option to achieve so.

    Can you help me out?

  • #2
    You don't say how you want to do that, but it's easy. Here is one way and there are others. You count the number of observations that are shown and then add that as a note().

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . count if !missing(mpg, weight)
       74
    
    . ret li
    
    scalars:
                      r(N) =  74
    
    . scatter mpg weight, note(`r(N)' observations)
    At a more advanced level you can customise what you want to show with your own command for an enhanced plot. aaplot (SSC) is indicative (but not definitive; for example, some people would want to show P-values, which I tend to resist).

    Much depends on what "several" means. If it is 3 or 7, just adding numbers almost by hand is practical. If it's 300 or 700, you will want an automated script.

    Comment

    Working...
    X