Announcement

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

  • fvpercent not generating the desired percentages


    I'm generating a crosstable of one column variable and multiple row variables. I want the percentages of the sub categories of the row variables as crosses with the column variable to be displayed. For example, what percentage of voters between the ages of 18 and 30 are swing voters as against those of the same category that are core voters? When added up, the two percentages should sum up to 100% as I indicated in the last column in the table below. Unfortunately, the fvpercent command is not producing percentages along that line. Instead, the percentages appear to be those of the column variable. Any help? table (var) (swing_voter), statistic(fvpercent age gender marital_status) nototals /// style(Table-1)
    Voted for the same party
    core swing Total percentage
    Age
    18-30 31.65 26.19 100
    31-40 32.98 37.81 100
    41-50 20.04 19.55 100
    51-60 11.35 11.32 100
    60+ 3.98 5.13 100
    Gender
    Male 49.63 51.7 100
    Female 50.37 48.3 100
    Marital Status
    unmarried 37.96 36.68 100
    married 62.04 63.32 100
    Location of Constituency
    Urban 50 48.3 100
    Rural 50 51.7 100




    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(swing_voter age gender marital_status)
    0 1 1 0
    1 4 1 1
    0 2 2 1
    0 1 2 1
    0 1 2 0
    1 2 1 1
    0 3 2 1
    0 5 2 1
    0 3 2 1
    0 1 1 1
    0 2 1 1
    1 2 1 0
    0 5 2 1
    1 3 1 1
    0 2 1 0
    1 1 2 0
    0 4 2 1
    0 2 1 0
    1 2 2 0
    0 3 2 0
    0 2 2 1
    0 2 2 0
    0 2 2 1
    0 5 1 1
    0 1 1 1
    0 4 1 1
    1 2 1 0
    0 4 1 1
    1 2 1 0
    0 1 1 0
    1 1 1 0
    0 1 1 0
    0 1 1 1
    1 2 1 1
    0 1 2 0
    1 4 1 1
    0 2 1 1
    1 2 1 1
    0 3 1 1
    0 1 1 0
    0 2 1 1
    0 1 2 1
    0 2 1 1
    0 2 2 0
    0 1 1 0
    1 1 1 0
    1 1 2 0
    0 1 2 0
    1 4 1 1
    1 1 1 0
    0 4 1 1
    0 3 1 1
    0 5 2 1
    0 2 1 1
    0 3 1 1
    0 2 1 1
    1 1 2 0
    1 2 2 1
    1 1 1 0
    0 2 2 1
    0 1 1 1
    0 2 1 1
    0 3 1 1
    1 1 2 0
    0 3 2 0
    1 4 1 1
    0 5 2 0
    0 4 2 1
    1 3 1 1
    0 2 2 1
    1 2 2 0
    0 1 2 1
    1 1 2 0
    1 1 1 0
    0 3 1 1
    0 2 2 1
    1 3 1 1
    1 3 2 1
    0 2 2 0
    0 1 1 0
    0 1 2 0
    0 4 1 1
    0 1 1 0
    0 5 1 1
    0 2 1 1
    1 1 1 0
    0 4 1 1
    1 2 1 1
    0 2 2 1
    1 2 2 1
    0 1 1 0
    1 2 2 0
    0 4 2 0
    1 4 1 1
    0 2 2 0
    1 4 1 1
    1 2 2 0
    0 3 1 1
    0 2 1 0
    1 1 1 1
    end
    label values swing_voter swingvoter
    label def swingvoter 0 "core", modify
    label def swingvoter 1 "swing", modify
    label values age labels0
    label def labels0 1 "18-30", modify
    label def labels0 2 "31-40", modify
    label def labels0 3 "41-50", modify
    label def labels0 4 "51-60", modify
    label def labels0 5 "60+", modify
    label values gender labels1
    label def labels1 1 "Male", modify
    label def labels1 2 "Female", modify
    label values marital_status marriage
    label def marriage 0 "unmarried", modify
    label def marriage 1 "married", modify

  • #2
    Try this

    Code:
    table (var) (swing_voter), statistic(percent i.age i.gender i.marital_status, across(swing_voter))  style(Table-1)
    Result

    Code:
    -----------------------------------------
                   |        swing_voter      
                   |    core   swing    Total
    ---------------+-------------------------
               age |                         
           18-30   |   61.29   38.71   100.00
           31-40   |   62.86   37.14   100.00
           41-50   |   71.43   28.57   100.00
           51-60   |   57.14   42.86   100.00
             60+   |  100.00    0.00   100.00
            gender |                         
            Male   |   61.02   38.98   100.00
          Female   |   70.73   29.27   100.00
    marital_status |                         
       unmarried   |   56.10   43.90   100.00
         married   |   71.19   28.81   100.00
    -----------------------------------------

    Comment


    • #3
      Thank you so much, Leonardo Guizzetti. That's exactly what I wanted.

      Comment

      Working...
      X