Announcement

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

  • Replicating a paper's Stacked Horizontal Bar graph

    I have the following data:

    ```
    dataex nationality economic_activity change
    input str15 nationality str33 economic_activity long change
    "foreign" "Agriculture, forestry and fishing" 4945
    "foreign" "Mining and quarrying" -13730
    "foreign" "Manufacturing" -169127
    "foreign" "Construction" -1802976
    "foreign" "Retail/trade" -600744
    "foreign" "Total (all sectors)" -1857160
    "national_male" "Agriculture, forestry and fishing" -961
    "national_male" "Mining and quarrying" 11407
    "national_male" "Manufacturing" 528
    "national_male" "Construction" -123294
    "national_male" "Retail/trade" 5815
    "national_male" "Total (all sectors)" 23689
    "national_female" "Agriculture, forestry and fishing" 407
    "national_female" "Mining and quarrying" 1920
    ```

    And I am trying to a graph similar to the one below:




    My current code is below:

    ```
    graph hbar (mean) change, over( nationality ) over( economic_activity )
    ```
    which produces the graph in the file attached, which is close to the graph above, but not quite the same.
    Attached Files

  • #2
    There are some errors in the data. 4945 should be -4945. -123934 should be 123934. There is no total for Saudi females.


    This may help:


    Code:
    clear
    input str15 nationality str33 economic_activity long change
    "foreign" "Agriculture, forestry and fishing" -4945
    "foreign" "Mining and quarrying" -13730
    "foreign" "Manufacturing" -169127
    "foreign" "Construction" -1802976
    "foreign" "Retail/trade" -600744
    "foreign" "Total (all sectors)" -1857160
    "national_male" "Agriculture, forestry and fishing" -961
    "national_male" "Mining and quarrying" 11407
    "national_male" "Manufacturing" 528
    "national_male" "Construction" 123294
    "national_male" "Retail/trade" 5815
    "national_male" "Total (all sectors)" 23689
    "national_female" "Agriculture, forestry and fishing" 407
    "national_female" "Mining and quarrying" 1920
    "national_female" "Total (all sectors)" 2327
    end
    
    separate change, by(nationality) veryshortlabel
    label variable change1 "Non-Saudis"
    label variable change2 "Saudi women"
    label variable change3 "Saudi men"
    graph hbar (mean) change1 change3 change2,  over(economic_activity) stack legend(order(1 "Non-Saudis" 2 "Saudi men" 3 "Saudi women"))  ///
    bar(1, color(ltblue)) bar(2, color(navy)) bar(3, color(orange_red)) yla(-2e6 "2 m" -15e5 "1.5 m" -1e6 "1 m" -5e5 "500000" 0)  ytitle(Change)
    The unstacked version looks clearer to me.

    Please note our request here for full real names, typically a family name and a given name. This was flagged previously to you in https://www.statalist.org/forums/for...n-monthly-data
    Last edited by Nick Cox; 10 Jun 2021, 23:53.

    Comment

    Working...
    X