Announcement

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

  • Access underlying data from graphs

    Hi there,

    Somewhat unusual question -- I'm working on a report that will include graphs originally produced in Stata, but we'd like to make them look fancy using a designer who doesn't use Stata. We can of course generate the table equivalent of any graph we've created in Stata, but it would be much easier if there was some way to ask Stata to extract the values that a graph represents.

    For example...

    Code:
    sysuse auto, clear
    graph bar (mean) mpg, over(foreign)
    Obviously in this example its trivial to get the underlying values (Domestic: 19.8, Foreign: 24.8), but it would be fantastic if there was some way to be able to automate the extraction of this type of data for more complicated graphs, without having to think through how to create the table version of every graph.

    Vague and likely impossible I know, but worth a try, maybe??

  • #2
    Not vague or impossible. What you want is the (relatively) obscure serset command described by help serset and more so in the Stata Programming Reference PDF included in your Stata installation and accessible from Stata's Help menu.
    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    . graph bar (mean) mpg, over(foreign)
    
    . serset dir
    
      0.  2 observations on 3 variables
          _values _variables foreign
    
    . serset use
    
    . describe
    
    Contains data
     Observations:             2                  
        Variables:             3                  
    ------------------------------------------------------------------------------------------------
    Variable      Storage   Display    Value
        name         type    format    label      Variable label
    ------------------------------------------------------------------------------------------------
    _values         double  %10.0g                
    _variables      long    %12.0g                
    foreign         float   %9.0g                 
    ------------------------------------------------------------------------------------------------
    Sorted by: 
    
    . list, clean abbreviate(12)
    
             _values   _variables   foreign  
      1.   19.826923            1         1  
      2.   24.772728            1         2  
    
    .

    Comment


    • #3
      I have found gph2xl to be a useful adjunct to serset.
      Code:
      search gph2xl
      gph2xl from http://digital.cgdev.org/doc/stata/MO/Misc
          `gph2xl'. Extract and export data and image from a -gph- file / Stata's
          graph commands sometimes generate and plot data derived from, / but not
          found within, the user's data set. In order to convey / to another
          researcher or a publisher the data used to generate an / existing

      Comment


      • #4
        These are fantastic, thank you William and Martyn!

        Comment

        Working...
        X