Announcement

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

  • line graphs of column percents from a crosstab

    I want to have multiple lines on one graph where each line is the set of column percentages from a two-way cross tab; here is a simplified table
    Code:
    sysuse auto
    
    . ta rep78 fore, mi col nofreq
    
        Repair |
        Record |       Car type
          1978 |  Domestic    Foreign |     Total
    -----------+----------------------+----------
             1 |      3.85       0.00 |      2.70
             2 |     15.38       0.00 |     10.81
             3 |     51.92      13.64 |     40.54
             4 |     17.31      40.91 |     24.32
             5 |      3.85      40.91 |     14.86
             . |      7.69       4.55 |      6.76
    -----------+----------------------+----------
         Total |    100.00     100.00 |    100.00
    I want two lines on my graph one for Domestic cars and one for Foreign

    the above is simplified in that my real example will have 6 columns rather than 2

  • #2
    Does this help?

    Code:
    sysuse auto, clear 
    
    * -groups- is from Stata Journal 
    groups foreign rep78, percent(foreign) missing fillin saving(goldstein, replace) 
    
    use goldstein  
    
    su rep78, meanonly
    local MAX = r(max) + 1
    replace rep78 = `MAX' if rep78 == .
    label def rep78 `MAX' "missing", modify
    label val rep78 rep78
    
    * -sepscatter- is from SSC
    sepscatter _percent rep78, separate(foreign) recast(line) xla(1/`MAX', valuelabel) yla(, format(%2.0f))
    Click image for larger version

Name:	forrich.png
Views:	1
Size:	21.8 KB
ID:	1457900


    Comment


    • #3
      it looks good in your example Nick but here is what I got when I tried on my data:
      Code:
      . groups dv14_gg0130a_sc_eating av14_gg0130a_sc_eating if inlist(av14_gg0130a_sc_eat
      > ing,"","-","07","09","88","01"), percent(av14_gg0130a_sc_eating) missing fillin sa
      > ving(goldstein, replace)
      file goldstein.dta not found
      r(601);
      so, no file saved

      when I changed the "saving" option by deleting ", replace", I received the following:
      Code:
      . groups dv14_gg0130a_sc_eating av14_gg0130a_sc_eating if inlist(av14_gg0130a_sc_eat
      > ing,"","-","07","09","88","01"), percent(av14_gg0130a_sc_eating) missing fillin sa
      > ving(goldstein)
      not sorted
      r(5);
      I have no idea what is causing either problem

      Comment


      • #4
        What happens when you go

        Code:
        which groups
        The latest public version is 1.4.1. I will send you 1.4.2 privately.

        Comment


        • #5
          thanks for the update - that solved the second problem ("not sorted") but not the first ("file ... not found"); because my variables were strings, the sepscatter did not work at all, but I am overcoming that

          Comment


          • #6
            I'd use
            Code:
             encode
            or
            Code:
             egen, group().

            Comment


            • #7
              thanks - appears to work fine now (and the issue with "saving, replace" disappears when the file exists (from a previous run, e.g.)

              Comment

              Working...
              X