Announcement

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

  • Tabout+graph dummy variables

    Hi,

    I'd like to generate two, or three-way tables and graphs using tabout and graph, but without displaying the "0" value. My current code (for the two-way table) is:
    Code:
    tabout VAR MALE using "TABLE'.tex", append f(0c) style(tex) font(bold) bt lines(none) h1(nil) h2(nil) cells(col) ptotal(none) h3("\midrule \textbf{TABLE: TABLE} \\")
    graph bar, over(VAR) over(MALE) asyvars blabel(bar, format(%9.0f)) percentages title("TABLE") ytitle("Percentage") name(g1, replace)
    where VAR=0 or VAR=1. I would like to only display the percentages for VAR==1.

    Thank you

  • #2
    Given a 0, 1 variable the fraction of 1s is just equal to the mean, just as the mean of 0 0 0 0 0 0 0 1 1 1 is 0.3. So

    Code:
    graph bar MALE, over(VAR)  asyvars
    should be closer to what you want. To see percents not fractions or proportions, just spell out what you want to see as a variation on

    Code:
    yla(0 .25 “25” .5 “50” .75 “75” 
    1 “100”)
    paying attention to the axis title at the same time. By the same token tabulate will display the mean of MALE for any other variable.

    Comment


    • #3
      Here is a demonstration script you can run yourself, including some small tricks, one undocumented if I recall correctly.

      Code:
      sysuse auto, clear
      
      graph bar foreign, over(rep78) ytitle("% foreign") yla(0 .20 "20" .4 "40" .6 "60" .8 "80", ang(h))  b1title(Repair record 1978) name(bar, replace) 
      
      graph dot foreign, over(rep78) ytitle("% foreign") yla(0 .20 "20" .4 "40" .6 "60" .8 "80") ysc(r(-0.02 .)) linetype(line) lines(lc(gs8) lw(vthin)) l1title(Repair record 1978)  name(dot, replace) 
      
      graph dot foreign, over(rep78) ytitle("% foreign") yla(0 .20 "20" .4 "40" .6 "60" .8 "80", ang(h)) ysc(r(-0.02 .)) linetype(line) lines(lc(gs8) lw(vthin)) b1title(Repair record 1978) vertical name(dotv, replace)

      Comment

      Working...
      X