Announcement

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

  • Combining multiple variables from multiple country datasets into one graph

    Hi All,

    Many thanks for this great avenue. Using Stata14, I am am working on multiple country-specific surveys that measured household catastrophic expenditure at 10% and 40% of food and non-food expenditure. This two outcome variables is to be dis-aggregated by location (urban/rural), quintiles (n5). I am trying to reproduce a similar graph to the one attached for the 26 countries of interest. How do I reproduce this? What is the attached sample graph called?How can i combine two different datasets into one graph since I cannot merge the datasets.

    I have attached the sample graph, the sample dataset for two countries. Below is my current code for a graph bar.

    Any ideas on how to do this would be great
    [graph bar cata_nf_40 cata_tot_10 [pw=popweight], over(hh_nexpcap_quintile, sort(cata_nf_40) descending label(labsize(medsmall))) ylabel(0(0.1).3)bar(1, color("7 111 106")) bar(2, color("196 252 245")) legend(label(1 "CATA40 non-food expenditure") label(2 "CATA10 total expenditure")) plotregion(color(white)) graphregion(fcolor(white) lcolor(black) ifcolor(white) ilpattern(solid)) ytitle("Proportion of CATA by wealth quintile", size(medsmall))title("CATA by wealth quintile", lpattern(solid) alignment(default) size(medium) color(black))
    graph save cata_quintile, replace
    graph bar cata_nf_40 cata_tot_10[pw=popweight], over(hh_urban,sort(cata_nf_40) descending label(labsize(medsmall)))ylabel(0(0.1)0.3)bar(1, color("7 111 106")) bar(2, color("196 252 245")) legend(label(1 "CATA40 non-food expenditure") label(2 "CATA10 total expenditure")) plotregion(color(white)) graphregion(fcolor(white) lcolor(black) ifcolor(white) ilpattern(solid)) ytitle("Proportion of CATA by location", size(medsmall))title("CATA by location", lpattern(solid) alignment(default) size(medium) color(black))
    graph save cata_urban, replace

    grc1leg cata_quintile.gph cata_urban.gph, rows(1) plotregion(color(white)) graphregion(fcolor(white) lcolor(black) ifcolor(white) ilpattern(solid)) title("Catastrophic health expenditure at 10% total and 40% non-food consumption expenditure", size(medium) lwidth(medthin) lpattern(solid) alignment(default) color(black))
    graph save cata,replace][/CODE]

    [* Example generated by -dataex-. To install: ssc install dataex
    clear
    input float popweight byte hh_region float hh_urban byte hh_nexpcap_quintile float(cata_tot_10 cata_nf_40)
    2897.155 1 0 2 1 0
    26074.395 1 0 1 0 0
    2897.155 1 0 5 0 1
    8691.465 1 0 3 0 0
    5794.31 1 0 5 0 0
    11588.62 1 0 2 0 0
    12228.253 1 0 1 0 0
    14485.775 1 0 5 0 0
    20280.086 1 0 5 0 0
    14485.775 1 0 2 0 0
    17449.373 1 0 3 0 1
    19942.14 1 0 4 0 0
    22434.91 1 0 5 0 0
    17449.373 1 0 3 0 0
    22434.91 1 0 4 0 0
    22434.91 1 0 4 0 0
    22434.91 1 0 4 0 0
    12463.838 1 0 2 0 0
    14956.605 1 0 1 . .
    4985.535 1 0 4 0 0
    4057.28 1 1 1 0 0
    5409.707 1 1 2 0 0
    4057.28 1 1 5 0 0
    5409.707 1 1 4 0 0
    5409.707 1 1 5 0 0
    5409.707 1 1 1 0 0
    5409.707 1 1 4 0 0
    8114.561 1 1 4 0 0
    4057.28 1 1 4 0 1
    1352.4268 1 1 4 0 0
    4057.28 1 1 5 0 0
    11915.287 1 0 1 0 0
    19858.81 1 0 1 0 0
    15887.05 1 0 1 0 0
    7943.524 1 0 2 0 0
    2336.3303 1 0 4 0 0
    7943.524 1 0 1 0 0
    23830.574 1 0 2 0 0
    3971.762 1 0 1 0 0
    15887.05 1 0 1 0 0
    35745.86 1 0 1 0 0
    27802.336 1 0 1 0 0
    19609.8 1 0 2 0 0
    39219.6 1 0 2 0 0
    27453.72 1 0 2 0 0
    19609.8 1 0 2 0 1
    19609.8 1 0 3 0 0
    9965.638 1 0 5 0 0
    19609.8 1 0 3 0 0
    11765.88 1 0 5 0 0
    23531.76 1 0 2 0 0
    6852.334 1 0 3 0 1
    270.48685 1 0 2 0 0
    27409.336 1 0 5 0 0
    27409.336 1 0 2 0 0
    17130.836 1 0 3 0 0
    23983.17 1 0 1 0 0
    20557 1 0 1 0 0
    13704.668 1 0 2 0 0
    27409.336 1 0 5 0 0
    1352.4342 1 0 2 0 0
    6852.334 1 0 3 0 0
    4280.7036 1 1 5 0 0
    4280.7036 1 1 5 0 0
    25684.22 1 1 4 0 0
    17122.814 1 1 3 0 0
    8561.407 1 1 5 0 0
    4280.7036 1 1 4 0 0
    29964.926 1 1 3 0 0
    12842.11 1 1 4 0 0
    4280.7036 1 1 5 0 0
    8561.407 1 1 4 1 1
    4280.7036 1 1 5 0 0
    12842.11 1 1 5 0 0
    19922.89 1 0 2 0 0
    6640.964 1 0 4 0 0
    23243.373 1 0 1 0 0
    33204.82 1 0 1 0 0
    23243.373 1 0 1 0 0
    3320.482 1 0 2 0 0
    3320.482 1 0 4 0 0
    19922.89 1 0 3 0 0
    26563.855 1 0 2 0 0
    9961.445 1 0 1 0 0
    16602.41 1 0 1 0 0
    3563.957 1 1 4 0 0
    7127.914 1 1 5 0 0
    12473.85 1 1 5 0 0
    5345.935 1 1 5 0 0
    12473.85 1 1 2 0 0
    7127.914 1 1 4 1 1
    8909.892 1 1 5 0 0
    7127.914 1 1 5 0 0
    5345.935 1 1 5 0 0
    1781.9784 1 1 5 0 0
    3563.957 1 1 4 0 0
    1781.9784 1 1 5 0 0
    24911.64 1 0 1 0 0
    28470.45 1 0 2 0 0
    3558.806 1 0 4 0 0
    end
    label values hh_region HH_SAQ01
    label def HH_SAQ01 1 "Tigray", modify
    label values hh_nexpcap_quintile hh_nexpcap_quintile
    label def hh_nexpcap_quintile 1 "poorest", modify
    label def hh_nexpcap_quintile 2 "poorer", modify
    label def hh_nexpcap_quintile 3 "middle", modify
    label def hh_nexpcap_quintile 4 "richer", modify
    label def hh_nexpcap_quintile 5 "richest", modify
    CODE]
    Attached Files
    Last edited by Michal Onah; 01 Mar 2018, 12:34.

  • #2
    Welcome to Statalist.

    A comment on substance: while you perhaps cannot combine datasets from different countries using any version of the merge command, it seems likely that the append command would allow you to combine your country-specific datasets into a single dataset. You will likely need to use copies of each country's data, with the variables renamed as needed so they match in every dataset, and with a country identifier added to each. That is the direction I would expect to take with data such as yours.

    A comment on formatting on Statalist: it appears that you attempted to use dataex and code tags in your post, but apparently got them mismatched or something. The following examples may help you in your future posts.

    Commands surrounded by code delimiters

    [code]
    // sample code
    sysuse auto, clear
    describe
    [/code]

    will be presented in the post as the following:
    Code:
    // sample code
    sysuse auto, clear
    describe
    Output from dataex,

    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str18 make int price byte foreign
    "AMC Concord" 4099 0
    "AMC Pacer" 4749 0
    "AMC Spirit" 3799 0
    "Buick Century" 4816 0
    "Buick Electra" 7827 0
    end
    label values foreign origin
    label def origin 0 "Domestic", modify
    [/CODE]

    will be presented as
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str18 make int price byte foreign
    "AMC Concord"   4099 0
    "AMC Pacer"     4749 0
    "AMC Spirit"    3799 0
    "Buick Century" 4816 0
    "Buick Electra" 7827 0
    end
    label values foreign origin
    label def origin 0 "Domestic", modify

    Comment


    • #3
      Originally posted by William Lisowski View Post
      Welcome to Statalist.

      A comment on substance: while you perhaps cannot combine datasets from different countries using any version of the merge command, it seems likely that the append command would allow you to combine your country-specific datasets into a single dataset. You will likely need to use copies of each country's data, with the variables renamed as needed so they match in every dataset, and with a country identifier added to each. That is the direction I would expect to take with data such as yours.

      A comment on formatting on Statalist: it appears that you attempted to use dataex and code tags in your post, but apparently got them mismatched or something. The following examples may help you in your future posts.
      Thanks William for the suggestion and for pointing out my error in posting the code. Assuming I’m able to append all the 26 countries, do you perhaps know how I can generate a similar graph to the one I posted above? I thought it’s a dotplot but it’s not producing what I had hoped.

      Thanks again!

      Mich

      Comment


      • #4
        Using Stata14, I am am working on multiple country-specific surveys that measured household catastrophic expenditure at 10% and 40% of food and non-food expenditure. This two outcome variables is to be dis-aggregated by location (urban/rural), quintiles (n5). I am trying to reproduce a similar graph to the one attached for the 26 countries of interest. How do I reproduce this? What is the attached sample graph called?How can i combine two different datasets into one graph since I cannot merge the datasets.

        I have attached the sample graph, the sample dataset for two countries. Below is my current code for a graph bar.

        Any ideas on how to do this would be great

        Code:
        graph bar cata_nf_40 cata_tot_10 [pw=popweight], over(hh_nexpcap_quintile, sort(cata_nf_40) descending label(labsize(medsmall))) ylabel(0(0.1).3)bar(1, color("7 111 106")) bar(2, color("196 252 245")) legend(label(1 "CATA40 non-food expenditure") label(2 "CATA10 total expenditure")) plotregion(color(white)) graphregion(fcolor(white) lcolor(black) ifcolor(white) ilpattern(solid)) ytitle("Proportion of CATA by wealth quintile", size(medsmall))title("CATA by wealth quintile", lpattern(solid) alignment(default) size(medium) color(black))
        graph save cata_quintile, replace
        graph bar cata_nf_40 cata_tot_10[pw=popweight], over(hh_urban,sort(cata_nf_40) descending label(labsize(medsmall)))ylabel(0(0.1)0.3)bar(1, color("7 111 106")) bar(2, color("196 252 245")) legend(label(1 "CATA40 non-food expenditure") label(2 "CATA10 total expenditure")) plotregion(color(white)) graphregion(fcolor(white) lcolor(black) ifcolor(white) ilpattern(solid)) ytitle("Proportion of CATA by location", size(medsmall))title("CATA by location", lpattern(solid) alignment(default) size(medium) color(black))
        graph save cata_urban, replace
        
        grc1leg cata_quintile.gph cata_urban.gph, rows(1) plotregion(color(white)) graphregion(fcolor(white) lcolor(black) ifcolor(white) ilpattern(solid)) title("Catastrophic health expenditure at 10% total and 40% non-food consumption expenditure", size(medium) lwidth(medthin) lpattern(solid) alignment(default) color(black))
        graph save cata,replace
        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float popweight byte hh_region float hh_urban byte hh_nexpcap_quintile float(cata_tot_10 cata_nf_40)
        2897.155 1 0 2 1 0
        26074.395 1 0 1 0 0
        2897.155 1 0 5 0 1
        8691.465 1 0 3 0 0
        5794.31 1 0 5 0 0
        11588.62 1 0 2 0 0
        12228.253 1 0 1 0 0
        14485.775 1 0 5 0 0
        20280.086 1 0 5 0 0
        14485.775 1 0 2 0 0
        17449.373 1 0 3 0 1
        19942.14 1 0 4 0 0
        22434.91 1 0 5 0 0
        17449.373 1 0 3 0 0
        22434.91 1 0 4 0 0
        22434.91 1 0 4 0 0
        22434.91 1 0 4 0 0
        12463.838 1 0 2 0 0
        14956.605 1 0 1 . .
        4985.535 1 0 4 0 0
        4057.28 1 1 1 0 0
        5409.707 1 1 2 0 0
        4057.28 1 1 5 0 0
        5409.707 1 1 4 0 0
        5409.707 1 1 5 0 0
        5409.707 1 1 1 0 0
        5409.707 1 1 4 0 0
        8114.561 1 1 4 0 0
        4057.28 1 1 4 0 1
        1352.4268 1 1 4 0 0
        4057.28 1 1 5 0 0
        11915.287 1 0 1 0 0
        19858.81 1 0 1 0 0
        15887.05 1 0 1 0 0
        7943.524 1 0 2 0 0
        2336.3303 1 0 4 0 0
        7943.524 1 0 1 0 0
        23830.574 1 0 2 0 0
        3971.762 1 0 1 0 0
        15887.05 1 0 1 0 0
        35745.86 1 0 1 0 0
        27802.336 1 0 1 0 0
        19609.8 1 0 2 0 0
        39219.6 1 0 2 0 0
        27453.72 1 0 2 0 0
        19609.8 1 0 2 0 1
        19609.8 1 0 3 0 0
        9965.638 1 0 5 0 0
        19609.8 1 0 3 0 0
        11765.88 1 0 5 0 0
        23531.76 1 0 2 0 0
        6852.334 1 0 3 0 1
        270.48685 1 0 2 0 0
        27409.336 1 0 5 0 0
        27409.336 1 0 2 0 0
        17130.836 1 0 3 0 0
        23983.17 1 0 1 0 0
        20557 1 0 1 0 0
        13704.668 1 0 2 0 0
        27409.336 1 0 5 0 0
        1352.4342 1 0 2 0 0
        6852.334 1 0 3 0 0
        4280.7036 1 1 5 0 0
        4280.7036 1 1 5 0 0
        25684.22 1 1 4 0 0
        17122.814 1 1 3 0 0
        8561.407 1 1 5 0 0
        4280.7036 1 1 4 0 0
        29964.926 1 1 3 0 0
        12842.11 1 1 4 0 0
        4280.7036 1 1 5 0 0
        8561.407 1 1 4 1 1
        4280.7036 1 1 5 0 0
        12842.11 1 1 5 0 0
        19922.89 1 0 2 0 0
        6640.964 1 0 4 0 0
        23243.373 1 0 1 0 0
        33204.82 1 0 1 0 0
        23243.373 1 0 1 0 0
        3320.482 1 0 2 0 0
        3320.482 1 0 4 0 0
        19922.89 1 0 3 0 0
        26563.855 1 0 2 0 0
        9961.445 1 0 1 0 0
        16602.41 1 0 1 0 0
        3563.957 1 1 4 0 0
        7127.914 1 1 5 0 0
        12473.85 1 1 5 0 0
        5345.935 1 1 5 0 0
        12473.85 1 1 2 0 0
        7127.914 1 1 4 1 1
        8909.892 1 1 5 0 0
        7127.914 1 1 5 0 0
        5345.935 1 1 5 0 0
        1781.9784 1 1 5 0 0
        3563.957 1 1 4 0 0
        1781.9784 1 1 5 0 0
        24911.64 1 0 1 0 0
        28470.45 1 0 2 0 0
        3558.806 1 0 4 0 0
        end
        label values hh_region HH_SAQ01
        label def HH_SAQ01 1 "Tigray", modify
        label values hh_nexpcap_quintile hh_nexpcap_quintile
        label def hh_nexpcap_quintile 1 "poorest", modify
        label def hh_nexpcap_quintile 2 "poorer", modify
        label def hh_nexpcap_quintile 3 "middle", modify
        label def hh_nexpcap_quintile 4 "richer", modify
        label def hh_nexpcap_quintile 5 "richest", modify
        Attached Files

        Comment


        • #5
          Originally posted by William Lisowski View Post
          Welcome to Statalist.

          A comment on substance: while you perhaps cannot combine datasets from different countries using any version of the merge command, it seems likely that the append command would allow you to combine your country-specific datasets into a single dataset. You will likely need to use copies of each country's data, with the variables renamed as needed so they match in every dataset, and with a country identifier added to each. That is the direction I would expect to take with data such as yours.
          Also, How can can I generate one variable that will look at those with CATA10 for 5 quintiles, CATA40 for 5 quintiles, CATA10 for urban/rural, and CATA40 for urban/rural in a way that I can append the multiple datasets and be able to plot a graph? I tried using the two options below for quintiles but I am not getting an ideal output

          Code:
          *CATA40 QUINTILES
          gen cata40_q1 =1 if cata_nf_40==1 & hh_nexpcap_q1==1
          replace cata40_q1=0 if cata_nf_40==1 & hh_nexpcap_q1==0
          
          gen cata40_q2=1 if cata_nf_40==1 & hh_nexpcap_q2==1
          replace cata40_q2=0 if cata_nf_40==1 & hh_nexpcap_q2==0
          
          gen cata40_q3=1 if cata_nf_40==1 & hh_nexpcap_q3==1
          replace cata40_q3=0 if cata_nf_40==1 & hh_nexpcap_q3==0
          
          gen cata40_q4=1 if cata_nf_40==1 & hh_nexpcap_q4==1
          replace cata40_q4=0 if cata_nf_40==1 & hh_nexpcap_q4==0
          
          gen cata40_q5=1 if cata_nf_40==1 & hh_nexpcap_q5==1
          replace cata40_q5=0 if cata_nf_40==1 & hh_nexpcap_q5==0
          Code:
          gen cata40_q=1 if cata_nf_40==1 & hh_nexpcap_quintile==1
          replace cata40_q=2 if cata_nf_40==1 & hh_nexpcap_quintile==2
          replace cata40_q=3 if cata_nf_40==1 & hh_nexpcap_quintile==3
          replace cata40_q=4 if cata_nf_40==1 & hh_nexpcap_quintile==4
          replace cata40_q=5 if cata_nf_40==1 & hh_nexpcap_quintile==5

          Comment

          Working...
          X