Announcement

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

  • Emulate SAS graph-table in Stata

    Hi all,
    I am trying to emulate a graph that's coupled with a table in Stata that I've done for years in SAS. I've converted almost all my other code over to Stata but have not been able to figure out how to create a Stata graph that reproduces what I get from Proc Gchart in SAS which has descriptive stats lined up with the bars of a chart. To demonstrate I've redone my code with Stata's famous auto.dta file:

    The SAS code and what it produces is

    PROC GCHART data=auto;
    HBAR mpg / TYPE=PCT MIDPOINTS= 44 TO 12 BY -4
    maxis=axis1;
    title font='Times' height=.15 in
    'Distribution of mpg';
    title2 'Test for comparison with Stata';
    run;





    Click image for larger version

Name:	SAS Proc Gchart output.png
Views:	1
Size:	30.0 KB
ID:	1348720




    Now, I can get close. For example, to create a bar chart that - once I fool with the formatting which is clearly off in the following - would duplicate Gchart:

    hist mpg , percent ylabel( , angle(horizontal) ) horizontal bin(8) start(10) barwidth(2.95)


    Click image for larger version

Name:	Stata hist output.png
Views:	1
Size:	8.0 KB
ID:	1348721


    And I can, inelegantly, get the matching descriptive stats:

    . egen cmpg1 = cut(mpg), at(9.999(4)42)
    . tabulate cmpg1


    cmpg1 | Freq. Percent Cum.
    ------------+-----------------------------------
    9.999 | 2 2.70 2.70
    13.999 | 16 21.62 24.32
    17.999 | 25 33.78 58.11
    21.999 | 17 22.97 81.08
    25.999 | 7 9.46 90.54
    29.999 | 3 4.05 94.59
    33.999 | 3 4.05 98.65
    37.999 | 1 1.35 100.00
    ------------+-----------------------------------
    Total | 74 100.00



    But I'd like to output, like Gchart, the bar chart with the aligned descriptives so that aligned with each bar is that bar's frequency, cumulative freq, percent freq, and cumulative freq. I have to do this about 40 times looping over various subsets of data and so would like something automated. Any help would be appreciated!

    Thanks.

    Kurt
    Last edited by Kurt Beron; 09 Jul 2016, 13:10.

  • #2
    The images you've attached appear unreadable. I recommend attaching .png files as detailed in the FAQ Advice.

    Comment


    • #3
      Sorry, I thought I had - it worked in the Sandbox. I think I've fixed it above. Please let me know if they still don't show up as I see them OK.

      Kurt

      Comment


      • #4
        Hi,
        I'm just confirming that it is the difficulty of replicating the SAS code in Stata rather than the inability to see my graphics which is the reason suggestions haven't come. I know I tried for quite a while before posting so the silence seems to be confirmation. I can certainly continue this step with SAS for now.

        Comment


        • #5
          I can see your graphs. Adding text to graphs is quite possible, but adding text in right-aligned columns is fiddlier than I wanted to pursue. Chalk that one up to SAS.

          But in passing note http://www.statalist.org/forums/foru...updated-on-ssc and now my article in Stata Journal 16(2).

          Comment


          • #6
            Thanks, Nick. I'd read your latest Stata Journal article and that's what inspired me to post! I appreciate it.

            Comment

            Working...
            X