Announcement

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

  • Graphs for categorical variables

    Hello everyone,

    I am trying to create a bar graph for the number of people (or percentage of people) with high education by region (and sector) using a code
    Code:
     graph bar (mean) high_qual, by(region, total)
    However, Stata gives an error term "factor-variable operators not allowed r(101)". Since the data is coded into numbers for each region and type of qualification, I am struggling to create meaningful graphs in general.

    Hence my question is - is there a way of creating de-coded graphs for non-numerical data, such that instead of numbers you see categories?

    Hope my question makes sense! Thank you in advance

  • #2
    Data example please. But (mean) isn't going to give you counts or sums. It will give you proportions (fractions) if the original variable is (0, 1).

    Comment


    • #3
      Thank you, Nick Cox! Let's say if I used the tabulation command and want to represent the below data on a graph (e.g. a bar chart), how can I do that?

      Code:
      -> tabulation of high_qual by region  
      
      +----------------+
      | Key            |
      |----------------|
      |   frequency    |
      | row percentage |
      +----------------+
      
                  Highest |
           qualification, |
             UKHLS & BHPS |                           Government Office Region
                  samples | North Eas  North Wes  Yorkshire  East Midl  West Midl  East of E     London |     Total
      --------------------+-----------------------------------------------------------------------------+----------
                   Degree |     3,030      8,997      6,824      5,719      7,054      8,075     17,209 |    95,592 
                          |      3.17       9.41       7.14       5.98       7.38       8.45      18.00 |    100.00 
      --------------------+-----------------------------------------------------------------------------+----------
      Other higher degree |     1,465      4,632      3,453      3,246      3,615      3,760      4,789 |    45,166 
                          |      3.24      10.26       7.65       7.19       8.00       8.32      10.60 |    100.00 
      --------------------+-----------------------------------------------------------------------------+----------
              A-level etc |     3,231      8,318      6,989      6,388      6,472      6,478      9,409 |    81,845 
                          |      3.95      10.16       8.54       7.80       7.91       7.91      11.50 |    100.00 
      --------------------+-----------------------------------------------------------------------------+----------
                 GCSE etc |     3,084      8,000      7,185      6,216      6,480      7,146      7,847 |    78,511 
                          |      3.93      10.19       9.15       7.92       8.25       9.10       9.99 |    100.00 
      --------------------+-----------------------------------------------------------------------------+----------
      Other qualification |     1,317      3,392      3,022      2,956      3,187      3,114      3,799 |    35,122 
                          |      3.75       9.66       8.60       8.42       9.07       8.87      10.82 |    100.00 
      --------------------+-----------------------------------------------------------------------------+----------
         No qualification |     1,734      4,683      4,354      3,668      4,668      3,701      4,535 |    47,835 
                          |      3.62       9.79       9.10       7.67       9.76       7.74       9.48 |    100.00 
      --------------------+-----------------------------------------------------------------------------+----------
                    Total |    13,861     38,022     31,827     28,193     31,476     32,274     47,588 |   384,071 
                          |      3.61       9.90       8.29       7.34       8.20       8.40      12.39 |    100.00

      Comment


      • #4
        graph bar can do that. Also catplot (SSC), tabplot (Stata Journal), etc. Many, many examples in this forum,

        For what we mean by data example, please see https://www.statalist.org/forums/help#stata

        The output from

        Code:
        preserve
        contract region high_qual
        dataex 
        restore
        would work well enough,
        Last edited by Nick Cox; 11 Mar 2022, 11:54.

        Comment


        • #5
          right, thank you so much for your help - really appreciate it! Nick Cox

          Comment

          Working...
          X