Announcement

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

  • Bar Chart with Multiple Bars (Grouped by Different Variables)

    Dear all,

    I have cross-sectional data including the variables below. I need to generate a four-column vertical bar chart (with percentages) for the variable aid, grouped by

    First Bar: Muslim" and others
    Second Bar: Arab League" and others
    Third Bar: Income Groups (HICs, UMICs, LMICs, and LDCs)
    Four Bar: Regions (South of Africa and others).

    May you help me to generate such a four-column bar chart?

    Thank you so much,

    Best,


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float aid byte(muslimmajority arableague) str5 incomegr str15 region
         . 0 . ""      ""              
         . 0 . ""      ""              
      4.82 1 0 "LDCs"  "SCA"            
         0 0 0 "LDCs"  "South of Africa"
         . 0 . ""      ""              
       .79 1 0 "UMICs" "Europe"        
         0 0 0 "HICs"  "Europe"        
         . 0 . ""      ""              
         . 0 . ""      ""              
       .07 0 0 "UMICs" "South America"  
         0 0 0 "LMICs" "SCA"            
         . 0 . ""      ""              
      5.05 0 0 "UMICs" "Caribbean"      
         0 0 0 "HICs"  "Ocenia"        
         0 0 0 "HICs"  "Europe"        
         0 1 0 "UMICs" "SCA"            
       .15 0 0 "LDCs"  "South of Africa"
         0 0 0 "HICs"  "Europe"        
         0 0 0 "LDCs"  "South of Africa"
         0 1 0 "LDCs"  "South of Africa"
         0 1 0 "LDCs"  "SCA"            
         0 0 0 "UMICs" "Europe"        
         0 1 1 "HICs"  "MENA"          
         0 0 0 "HICs"  "Caribbean"      
       .02 1 0 "UMICs" "Europe"        
      7.24 0 0 "UMICs" "Europe"        
       .01 0 0 "UMICs" "Central America"
         . 0 . ""      ""              
       .02 0 0 "LMICs" "South America"  
       .46 0 0 "UMICs" "South America"  
         0 0 0 "HICs"  "Caribbean"      
         0 1 0 "HICs"  "Far East"      
       .04 0 0 "LDCs"  "SCA"            
       .03 0 0 "UMICs" "South of Africa"
         0 0 0 "LDCs"  "South of Africa"
         0 0 0 "HICs"  "North America"  
         . 0 . ""      ""              
         0 0 0 "HICs"  "Europe"        
         0 0 0 "HICs"  "South America"  
       .16 0 0 "UMICs" "Far East"      
       .01 0 0 "LMICs" "South of Africa"
       .36 0 0 "LMICs" "South of Africa"
         0 0 0 "LDCs"  "South of Africa"
      1.53 0 1 "LMICs" "South of Africa"
         . 0 . ""      ""              
       .63 0 0 "UMICs" "South America"  
      21.3 1 1 "LDCs"  "South of Africa"
         0 0 0 "LMICs" "South of Africa"
       .07 0 0 "UMICs" "Central America"
      5.19 0 0 "UMICs" "Caribbean"      
         . 0 . ""      ""              
         . 0 . ""      ""              
         0 0 0 "HICs"  "MENA"          
         0 0 0 "HICs"  "Europe"        
         0 0 0 "HICs"  "Europe"        
       .03 1 1 "LDCs"  "South of Africa"
         0 0 0 "UMICs" "Caribbean"      
         0 0 0 "HICs"  "Europe"        
         0 0 0 "UMICs" "Caribbean"      
         0 1 1 "UMICs" "MENA"          
       .32 0 0 "UMICs" "South America"  
    245.81 1 1 "LMICs" "MENA"          
    192.67 0 0 "LDCs"  "South of Africa"
         . 0 . ""      ""              
         0 0 0 "HICs"  "Europe"        
         0 0 0 "HICs"  "Europe"        
     51.62 0 0 "LDCs"  "South of Africa"
         0 0 0 "HICs"  "Europe"        
         0 0 0 "UMICs" "Ocenia"        
         0 0 0 "HICs"  "Europe"        
         . 0 . ""      ""              
         0 0 0 "LMICs" "Ocenia"        
         0 0 1 "UMICs" "South of Africa"
         0 0 0 "HICs"  "Europe"        
       .01 0 0 "UMICs" "SCA"            
      1.47 0 0 "LMICs" "South of Africa"
         . 0 0 ""      ""              
      9.66 1 0 "LDCs"  "South of Africa"
      2.45 1 0 "LDCs"  "South of Africa"
       .03 0 0 "LDCs"  "South of Africa"
         0 0 1 "UMICs" "South of Africa"
         0 0 0 "HICs"  "Europe"        
         0 0 0 "UMICs" "Caribbean"      
         . 0 . ""      ""              
       .23 0 0 "LMICs" "Central America"
         . 0 . ""      ""              
         0 0 0 "UMICs" "South America"  
         . 0 . ""      ""              
       .18 0 0 "LMICs" "Central America"
         0 0 0 "HICs"  "Europe"        
       .05 0 0 "LDCs"  "Caribbean"      
         0 0 0 "HICs"  "Europe"        
        .8 1 0 "LMICs" "Far East"      
       .94 0 0 "LMICs" "SCA"            
         0 0 0 "HICs"  "Europe"        
       .01 1 1 "UMICs" "MENA"          
      3.31 1 1 "UMICs" "MENA"          
         0 0 0 "HICs"  "Europe"        
         0 0 0 "HICs"  "MENA"          
         0 0 0 "HICs"  "Europe"        
    end
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 224 observations
    Use the count() option to list more
    Last edited by Nihat Mugurtay; 26 May 2022, 07:19.

  • #2
    I am not really clear what you want here as only one of your variables has four distinct values and the others don't. So I don't follow what is to be a four-column chart other than that for incomegr.

    Vertical bars won't work well here for your region variable.

    This may help otherwise.: As in a previous thread of yours I flag that "Ocenia" is a typo.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float aid byte(muslimmajority arableague) str5 incomegr str15 region
         . 0 . ""      ""              
         . 0 . ""      ""              
      4.82 1 0 "LDCs"  "SCA"            
         0 0 0 "LDCs"  "South of Africa"
         . 0 . ""      ""              
       .79 1 0 "UMICs" "Europe"        
         0 0 0 "HICs"  "Europe"        
         . 0 . ""      ""              
         . 0 . ""      ""              
       .07 0 0 "UMICs" "South America"  
         0 0 0 "LMICs" "SCA"            
         . 0 . ""      ""              
      5.05 0 0 "UMICs" "Caribbean"      
         0 0 0 "HICs"  "Ocenia"        
         0 0 0 "HICs"  "Europe"        
         0 1 0 "UMICs" "SCA"            
       .15 0 0 "LDCs"  "South of Africa"
         0 0 0 "HICs"  "Europe"        
         0 0 0 "LDCs"  "South of Africa"
         0 1 0 "LDCs"  "South of Africa"
         0 1 0 "LDCs"  "SCA"            
         0 0 0 "UMICs" "Europe"        
         0 1 1 "HICs"  "MENA"          
         0 0 0 "HICs"  "Caribbean"      
       .02 1 0 "UMICs" "Europe"        
      7.24 0 0 "UMICs" "Europe"        
       .01 0 0 "UMICs" "Central America"
         . 0 . ""      ""              
       .02 0 0 "LMICs" "South America"  
       .46 0 0 "UMICs" "South America"  
         0 0 0 "HICs"  "Caribbean"      
         0 1 0 "HICs"  "Far East"      
       .04 0 0 "LDCs"  "SCA"            
       .03 0 0 "UMICs" "South of Africa"
         0 0 0 "LDCs"  "South of Africa"
         0 0 0 "HICs"  "North America"  
         . 0 . ""      ""              
         0 0 0 "HICs"  "Europe"        
         0 0 0 "HICs"  "South America"  
       .16 0 0 "UMICs" "Far East"      
       .01 0 0 "LMICs" "South of Africa"
       .36 0 0 "LMICs" "South of Africa"
         0 0 0 "LDCs"  "South of Africa"
      1.53 0 1 "LMICs" "South of Africa"
         . 0 . ""      ""              
       .63 0 0 "UMICs" "South America"  
      21.3 1 1 "LDCs"  "South of Africa"
         0 0 0 "LMICs" "South of Africa"
       .07 0 0 "UMICs" "Central America"
      5.19 0 0 "UMICs" "Caribbean"      
         . 0 . ""      ""              
         . 0 . ""      ""              
         0 0 0 "HICs"  "MENA"          
         0 0 0 "HICs"  "Europe"        
         0 0 0 "HICs"  "Europe"        
       .03 1 1 "LDCs"  "South of Africa"
         0 0 0 "UMICs" "Caribbean"      
         0 0 0 "HICs"  "Europe"        
         0 0 0 "UMICs" "Caribbean"      
         0 1 1 "UMICs" "MENA"          
       .32 0 0 "UMICs" "South America"  
    245.81 1 1 "LMICs" "MENA"          
    192.67 0 0 "LDCs"  "South of Africa"
         . 0 . ""      ""              
         0 0 0 "HICs"  "Europe"        
         0 0 0 "HICs"  "Europe"        
     51.62 0 0 "LDCs"  "South of Africa"
         0 0 0 "HICs"  "Europe"        
         0 0 0 "UMICs" "Ocenia"        
         0 0 0 "HICs"  "Europe"        
         . 0 . ""      ""              
         0 0 0 "LMICs" "Ocenia"        
         0 0 1 "UMICs" "South of Africa"
         0 0 0 "HICs"  "Europe"        
       .01 0 0 "UMICs" "SCA"            
      1.47 0 0 "LMICs" "South of Africa"
         . 0 0 ""      ""              
      9.66 1 0 "LDCs"  "South of Africa"
      2.45 1 0 "LDCs"  "South of Africa"
       .03 0 0 "LDCs"  "South of Africa"
         0 0 1 "UMICs" "South of Africa"
         0 0 0 "HICs"  "Europe"        
         0 0 0 "UMICs" "Caribbean"      
         . 0 . ""      ""              
       .23 0 0 "LMICs" "Central America"
         . 0 . ""      ""              
         0 0 0 "UMICs" "South America"  
         . 0 . ""      ""              
       .18 0 0 "LMICs" "Central America"
         0 0 0 "HICs"  "Europe"        
       .05 0 0 "LDCs"  "Caribbean"      
         0 0 0 "HICs"  "Europe"        
        .8 1 0 "LMICs" "Far East"      
       .94 0 0 "LMICs" "SCA"            
         0 0 0 "HICs"  "Europe"        
       .01 1 1 "UMICs" "MENA"          
      3.31 1 1 "UMICs" "MENA"          
         0 0 0 "HICs"  "Europe"        
         0 0 0 "HICs"  "MENA"          
         0 0 0 "HICs"  "Europe"        
    end
    
    replace region = "Oceania" if region == "Ocenia"
    label var muslim "Muslim majority" 
    label var arableague "Arab League" 
    label def yesno 1 Yes 0 No 
    label val muslim yesno 
    label val arab yesno 
    label var region "Region"
    label var incomegr "Income group"
    
    tokenize "muslim arableague incomegr region"
    
    forval j = 1/4 { 
        graph hbar (percent) aid, over(``j'') name(G`j', replace) l1title("`: var label ``j'''")
    } 
    
    graph combine G1 G2 G3 G4


    Comment


    • #3
      Dear Nick Cox ,

      This was very helpful.

      I am actually looking for this, I did this in Excel, but it takes a lot of time for me(taking totals etc). However, there might be a solution in STATA in a similar way you did. Perhaps a relevant syntax:

      Code:
      graph bar aid, over(incomegr, sort(order)) over(muslim) over(region, if region=="South of Africa" stack asyvars ..........
      Click image for larger version

Name:	uae.jpeg
Views:	1
Size:	559.8 KB
ID:	1666455


      Comment


      • #4
        Thanks for the clarification. That doesn't look especially easy in Stata, but someone else may see a good way to do it.

        PS Just fix that Ocenia to Oceania!

        Comment


        • #5
          Dear Nick Cox,

          Thank you so much for your response.
          Yes, I corrected "Oceania" =)

          I saw one example in Dreher et al (2018) article and replicated the figure. But, when I try to apply it to my own data, everything falls apart, with lots of syntax errors. Here, I attach their open replication data and STATA code from the same material. Actually, I can continue to do it in excel, but it inflates document size. Also, STATA makes it easy to link all the empirical output to Latex. It will great help if I apply this to my work.

          Best,

          N.


          Code:
          use "dragon_fruits.dta", clear
          keep if time>=2000 & time<2013
          
          ren time year
          
          gen OFn_othersec=OFn_all-OFn_soc-OFn_eco-OFn_pro-OFn_hum
          gen OFn_otherflo=OFn_all-OFn_grant-OFn_loan
          gen OFa_othersec=OFa_all-OFa_soc-OFa_eco-OFa_pro-OFa_hum
          gen OFa_otherflo=OFa_all-OFa_grant-OFa_loan
          
          collapse (sum) OFn_oda OFn_oofv OFn_soc OFn_eco OFn_pro OFn_hum OFn_othersec OFn_grant OFn_loan OFn_otherflo ///
              OFa_oda OFa_oofv OFa_soc OFa_eco OFa_pro OFa_hum OFa_othersec OFa_grant OFa_loan OFa_otherflo, by(year)
          
          reshape long OFn_ OFa_, i(year) j(flow) string
          collapse (sum) OFn_ OFa_, by(flow)
          replace OFa_=OFa_/1000000000
          
          gen type=flow
          replace type="flow class" if flow=="oda"
          replace type="flow class" if flow=="oofv"
          replace type="sector" if flow=="soc"
          replace type="sector" if flow=="eco"
          replace type="sector" if flow=="pro"
          replace type="sector" if flow=="hum"
          replace type="sector" if flow=="othersec"
          replace type="flow type" if flow=="grant"
          replace type="flow type" if flow=="loan"
          replace type="flow type" if flow=="otherflo"
          
          replace flow=" other " if flow=="othersec"
          replace flow="other" if flow=="otherflo"
          replace flow="social" if flow=="soc"
          replace flow="economic" if flow=="eco"
          replace flow="production" if flow=="pro"
          replace flow="humanitarian" if flow=="hum"
          replace flow="grants" if flow=="grant"
          replace flow="loans" if flow=="loan"
          replace flow="total" if flow=="all"
          replace flow="ODA" if flow=="oda"
          replace flow="OOF/vague" if flow=="oofv"
          
          gen order=OFn_
          replace order=0 if flow==" other "
          
          graph bar OFa_, over(flow, sort(order) descending) over(type) stack asyvars scheme(lean1) ytitle("Amount in billions of constant US$") ///
              /*blabel(name, position(center))*/ legend(off) intensity(0)
          *graph play dragon
          graph export "econometrics_tables\figure1.pdf", as(pdf) replace

          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input str51 recipient_iso3 str20 recipient_condensed long rid float time double(OFn_all OFn_oda OFn_oofv OFn_soc OFn_eco OFn_pro OFn_hum OFn_grant OFn_loan OFa_all OFa_oda OFa_oofv OFa_soc OFa_eco OFa_pro OFa_hum OFa_grant OFa_loan)
          "AGO" "Angola"               1 1997  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "AGO" "Angola"               1 1998  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "AGO" "Angola"               1 1999  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "AGO" "Angola"               1 2000  1 1  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "AGO" "Angola"               1 2001  4 3  1  3  0 0 1 3  1      51153442.9348         41176549.5       9976895           50155755             0           0      997689.5         41176549.5       9976895
          "AGO" "Angola"               1 2002  9 3  6  2  5 0 2 4  5     242687113.6864      2982400.59375     239704720        1487822.375     239704720           0 1494578.21875      2982400.59375     239704720
          "AGO" "Angola"               1 2003  2 1  1  1  0 0 0 0  2       501045172.68           17721854     483323328           17721854             0           0             0                  0     501045182
          "AGO" "Angola"               1 2004  5 1  4  1  2 0 0 1  4  87925246.99000001                  0      87925246                  0      87925246           0             0                  0      87925246
          "AGO" "Angola"               1 2005 34 4 30 22  7 4 0 1 33 1820770894.0589993        136575190.5  1684195700.5        899684372.5     558839866 353203387.5             0          1435869.5  1819335021.5
          "AGO" "Angola"               1 2006 16 2 14  6  6 3 0 2 14 1084031108.8932998         269160.125    1083761943      277468071.125     346133888   359123528             0         269160.125    1083761943
          "AGO" "Angola"               1 2007 28 4 24 13 12 2 0 3 24    1909305101.4048      8156769.40625 1901148340.25    419502638.90625 1376223375.25   105736048             0       313721.90625 1901148340.25
          "AGO" "Angola"               1 2008  2 0  2  0  2 0 0 0  2       107519651.38                  0     107519652                  0     107519652           0             0                  0     107519652
          "AGO" "Angola"               1 2009  1 0  1  0  0 1 0 0  1                  0                  0             0                  0             0           0             0                  0             0
          "AGO" "Angola"               1 2010  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "AGO" "Angola"               1 2011  2 2  0  2  0 0 0 2  0        256582.9522      256582.953125             0      256582.953125             0           0             0      256582.953125             0
          "AGO" "Angola"               1 2012  3 1  2  1  0 1 0 2  1        420240108.4                  0     420240096                  0             0           0             0                  0     420240096
          "AGO" "Angola"               1 2013  5 2  3  2  2 1 0 3  2      1240627614.44           29618440    1211009152           29618440    1211009152           0             0           29618440    1211009152
          "BDI" "Burundi"              2 1997  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BDI" "Burundi"              2 1998  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BDI" "Burundi"              2 1999  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BDI" "Burundi"              2 2000  1 1  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "BDI" "Burundi"              2 2001  2 2  0  0  0 0 0 1  0       80046109.439        80046109.75             0                  0             0           0             0         4017885.75             0
          "BDI" "Burundi"              2 2002  2 2  0  2  0 0 0 2  0                  0                  0             0                  0             0           0             0                  0             0
          "BDI" "Burundi"              2 2003  1 1  0  0  0 0 0 1  0        5839327.976            5839328             0                  0             0           0             0            5839328             0
          "BDI" "Burundi"              2 2004  2 1  1  1  1 0 0 1  1        11919302.31                  0      11919302                  0      11919302           0             0                  0      11919302
          "BDI" "Burundi"              2 2005  1 1  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "BDI" "Burundi"              2 2006  2 2  0  2  0 0 0 2  0        16892187.41           16892188             0           16892188             0           0             0           16892188             0
          "BDI" "Burundi"              2 2007  6 6  0  3  1 0 0 4  0      62780758.7048     62780757.65625             0      3099873.15625     4705828.5           0             0      7805701.65625             0
          "BDI" "Burundi"              2 2008  8 6  2  5  1 0 0 5  2 15243945.214000002           12949463  2294482.5625           10927210   1712426.625           0             0           10927210  2604308.9375
          "BDI" "Burundi"              2 2009  3 3  0  1  0 1 0 3  0                  0                  0             0                  0             0           0             0                  0             0
          "BDI" "Burundi"              2 2010  2 2  0  1  0 0 0 2  0        5492699.298          5492699.5             0                  0             0           0             0          5492699.5             0
          "BDI" "Burundi"              2 2011  4 2  2  1  1 0 0 3  1       19243721.415           19243722             0                  0             0           0             0            6414574      12829148
          "BDI" "Burundi"              2 2012  4 4  0  3  1 0 0 4  0 1298289.7044000002     1298289.671875             0      168096.046875   1130193.625           0             0     1298289.671875             0
          "BDI" "Burundi"              2 2013  2 2  0  1  1 0 0 2  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 1997  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 1998  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 1999  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2000  1 0  1  0  0 1 0 0  1         15683908.9                  0      15683909                  0             0    15683909             0                  0      15683909
          "BEN" "Benin"                3 2001  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2002  1 1  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2003  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2004  1 1  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2005  1 1  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2006  2 2  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2007  2 1  1  0  0 1 0 1  1        12548875.99          4705828.5     7843047.5                  0             0   7843047.5             0          7843047.5     4705828.5
          "BEN" "Benin"                3 2008  5 5  0  2  1 1 0 5  0       34785644.954           34785645             0                  0      23144526   5820559.5             0           34785645             0
          "BEN" "Benin"                3 2009  2 0  2  2  0 0 0 2  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2010  1 1  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2011  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2012  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BEN" "Benin"                3 2013  9 4  5  5  2 0 0 3  5      285547737.722       31108598.875     254439142       63268748.875     192660552           0             0        8894768.875     276652972
          "BFA" ""                     4 1997  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 1998  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 1999  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2000  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2001  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2002  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2003  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2004  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2005  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2006  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2007  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2008  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2009  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2010  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2011  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2012  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BFA" ""                     4 2013  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BWA" "Botswana"             5 1997  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BWA" "Botswana"             5 1998  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BWA" "Botswana"             5 1999  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BWA" "Botswana"             5 2000  2 1  1  1  0 0 1 1  1                  0                  0             0                  0             0           0             0                  0             0
          "BWA" "Botswana"             5 2001  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BWA" "Botswana"             5 2002  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "BWA" "Botswana"             5 2003  1 1  0  0  1 0 0 0  1        38928853.18           38928852             0                  0      38928852           0             0                  0      38928852
          "BWA" "Botswana"             5 2004  3 2  1  2  1 0 0 0  3         75409098.6           61093880      14315218           51883390      23525708           0             0                  0      75409098
          "BWA" "Botswana"             5 2005  2 2  0  1  0 0 0 1  1        5255248.003            5255248             0                  0             0           0             0                  0       5255248
          "BWA" "Botswana"             5 2006  2 1  1  2  0 0 0 1  1 12843433.628600001           12681938   161496.0625      12843434.0625             0           0             0        161496.0625      12681938
          "BWA" "Botswana"             5 2007  1 1  0  1  0 0 0 1  0        1568609.499          1568609.5             0          1568609.5             0           0             0          1568609.5             0
          "BWA" "Botswana"             5 2008  3 3  0  3  0 0 0 3  0        162921.1198         162921.125             0         162921.125             0           0             0         162921.125             0
          "BWA" "Botswana"             5 2009  8 7  1  4  1 1 0 8  0      4402656.83014   4402656.90234375             0     11180.77734375             0           0             0   4402656.90234375             0
          "BWA" "Botswana"             5 2010  2 2  0  1  0 0 0 2  0        5492699.298          5492699.5             0                  0             0           0             0          5492699.5             0
          "BWA" "Botswana"             5 2011  5 5  0  5  0 0 0 5  0      200076.853113 200076.85107421875             0 200076.85107421875             0           0             0 200076.85107421875             0
          "BWA" "Botswana"             5 2012  1 1  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "BWA" "Botswana"             5 2013  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 1997  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 1998  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 1999  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 2000  2 2  0  2  0 0 0 2  0                  0                  0             0                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 2001  0 0  0  0  0 0 0 0  0                  0                  0             0                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 2002  2 1  1  1  0 0 0 1  0        1997274.907                  0   1997274.875                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 2003  6 6  0  5  0 0 0 6  0      36354564.6295    36354563.609375             0    33582580.109375             0           0             0    36354563.609375             0
          "CAF" "Central African Rep." 6 2004  3 3  0  3  0 0 0 2  1        9945309.135            9945309             0            9945309             0           0             0            6027460       3917849
          "CAF" "Central African Rep." 6 2005  1 0  1  0  1 0 0 0  1         96863419.7                  0      96863416                  0      96863416           0             0                  0      96863416
          "CAF" "Central African Rep." 6 2006  3 2  1  2  0 0 0 2  1        7671063.256                  0     7671063.5                  0             0           0             0                  0     7671063.5
          "CAF" "Central African Rep." 6 2007  4 2  2  0  1 1 0 1  2      18728234.8684      14193600.9375       4534634                  0   499168.9375           0             0        499168.9375       4534634
          "CAF" "Central African Rep." 6 2008  2 2  0  2  0 0 0 2  0                  0                  0             0                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 2009  3 3  0  1  1 1 0 3  0                  0                  0             0                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 2010  1 1  0  1  0 0 0 1  0                  0                  0             0                  0             0           0             0                  0             0
          "CAF" "Central African Rep." 6 2011  2 2  0  1  1 0 0 1  1       32499859.923         32499859.5             0          7905371.5      24594488           0             0          7905371.5      24594488
          end
          label values rid rid
          label def rid 1 "AGO", modify
          label def rid 2 "BDI", modify
          label def rid 3 "BEN", modify
          label def rid 4 "BFA", modify
          label def rid 5 "BWA", modify
          label def rid 6 "CAF", modify
          ------------------ copy up to and including the previous line ------------------

          Listed 100 out of 901 observations
          Use the count() option to list more

          Comment


          • #6
            After collapsing, I need to have a data structure like the below to run the final command to plot a bar chart.

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            clear
            input str12 category double aidpercent str10 type
            "muslim"     80 "Religion"
            "other"      20 "Religion"
            "arableague" 70 "Arab"    
            "other"      30 "Arab"    
            "HICs"       20 "Income"  
            "LMICs"      30 "Income"  
            "UMICs"      25 "Income"  
            "LDCs"       25 "Income"  
            "Africa"     45 "Region"  
            "Other"      55 "Reigon"  
            end
            ------------------ copy up to and including the previous line ------------------

            Listed 10 out of 10 observations

            Comment


            • #7
              Indeed, that is what you need. As I don't think the result in #3 is superior to that implied by #2 -- indeed you had to suppress a lot of possibly interesting detail to get to a readable result in #3 -- I don't have personal incentive to write Stata code towards it.

              Naturally the field is wide open to others.

              Comment


              • #8
                Dear Nick Cox ,

                Thank you for your valuable suggestions, I will definitely use #2 at one point in my dissertation.

                Meanwhile, I primitively solved the puzzle by using "collapse" four times, then used the code below to plot the bar chart. At least, I got what I did using Excel #3. Unfortunately, I manually handled labeling operations.



                for COLLAPSE (I did the same for region, religion, Arab league, and incomegr)

                Code:
                collapse (sum) aid2019, by (incomegr)

                DATA:

                Code:
                * Example generated by -dataex-. For more info, type help dataex
                clear
                input str9 class double aid2019 str11 category
                "LDCs"       1316.959987366572 "IncomeGr"   
                "LMICs"      668.3299905415624 "IncomeGr"   
                "UMICs"     241.41999356262386 "IncomeGr"   
                "Muslim"    1685.8399819172919 "Religion"   
                "Other"     498.00999012589455 "Religion"   
                "Africa"    1143.1999990548939 "Region"     
                "Caribbean"  10.56000023894012 "Region"     
                "Oceania"    .4100000113248825 "Region"     
                "Other"     1029.6799727380276 "Region"     
                "Member"    1284.2799829915166 "Arab League"
                "Other"      899.5699890516698 "Arab League"
                end
                ------------------ copy up to and including the previous line ------------------

                Listed 11 out of 11 observations


                FOR BAR CHART:

                Code:
                graph bar aid2019 , over(class) over(category) stack asyvars scheme(lean1) ytitle("Amount in millions of constant US$") legend(off) intensity(0)

                Comment

                Working...
                X