Announcement

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

  • Graphing cumulative frequency using string variable from tab data

    Hello everyone,

    I am quite new to stata so please forgive me if this is a silly question

    I have used the tab command to create a table which looks something like this

    Code:
    tab industrycode if dummyvariable==1, sort
    which gives me a table that looks like this

    Code:
       Industry |    Freq.     Percent        Cum.
    ------------+-----------------------------------
              A |        294       31.99       31.99
              D |         90        9.79       41.78
              Z |         67        7.29       49.08
              Q |         63        6.86       55.93
              P |         55        5.98       61.92
              C |         51        5.55       67.46
              N |         50        5.44       72.91
              G |         40        4.35       77.26
    and so on....

    I was wondering if there is a way to graph this on a cumulative frequency plot where I can see which industry codes are in the top and bottom quartiles? As in Industry Letter on X axis and the cumulative frequency on Y.
    The codes I try to use tell me that because industry codes are string they cannot be used.

    Any help is appreciated!!

  • #2
    contract the dataset so that you have the frequencies as a variable.

    Code:
    contract Industry if dummyvariable==1
    Then you can proceed as follows:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str2 Industry float _freq
    "A" 294
    "C"  51
    "D"  90
    "G"  40
    "N"  50
    "P"  55
    "Q"  63
    "Z"  67
    end
    
    gsort -_freq
    gen cumul= sum(_freq)
    local which
    forval i=1/`=_N'{
        local which "`which' `i' `=Industry[`i']'"
     }
    lab def which `which'
    encode Industry, g(industry) label(which)
    set scheme s1mono
    line cumul industry, xlab(1/8, val) ytitle("Cumulative Frequency") xtitle(Industry)
    Res.:

    Click image for larger version

Name:	Graph.png
Views:	1
Size:	27.6 KB
ID:	1670994



    I like your character in Better Call Saul, but see our strong preference for full real names https://www.statalist.org/forums/help#realnames. You can click on “Contact us” located at the bottom right-hand corner of the page and request that your name be changed.

    Comment

    Working...
    X