Announcement

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

  • how to produce share (%) of list of countries by sector

    I am using stata 14.2
    I would like to compute percentages instead of sum so that the total for each country sum to 100%. I need help on how to do this.
    I used "collapse" and "egen" but could not get what I am looking for,

    I used the following command to get the sum of values

    bys country: table sector, c(sum us), if status!=3, row col
    -> country = Afghanistan
    Sector sum(us)
    Agriculture 11.26
    Education 0.20
    Energy 17.73
    Finance 13.37
    Health 0.67
    Public Administration 0.17
    Transportation 114.06
    Total 157.45
    -> country = Albania
    Sector sum(us)
    Agriculture 40.16
    Education 1.00
    Finance 28.03
    Health 16.58
    Industry and Mining 5.26
    Transportation 480.15
    Water, Sanitation & Urban Services 27.45
    Real Estate 4.40
    Total 603.03

  • #2
    Check out

    Code:
    help egen
    Here's a stylized example:

    Code:
    clear 
    input str1 country category whatever 
    "A"  1  10 
    "A"  2  20 
    "A"  3  30 
    "A"  4  40
    "B"  1  100
    "B"  2  200
    "B"  3  300 
    "B"  4  400
    end 
    
    egen pc = pc(whatever), by(country) 
    
    tabdisp country category, c(pc) 
    
    ----------------------------------
              |        category       
      country |    1     2     3     4
    ----------+-----------------------
            A |   10    20    30    40
            B |   10    20    30    40
    ----------------------------------

    Comment

    Working...
    X