Announcement

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

  • Two way histogram


    Hello

    Could anyone please suggest a code in order to replicate this histogram for a panel data.

    In addition to that in a second graph I would like to add a second y line at the right with a second variable .

    Click image for larger version

Name:	Screen Shot 2021-10-27 at 22.07.29.png
Views:	4
Size:	84.9 KB
ID:	1633538





    Image Screen-Shot-2021-10-27-at-22-07-29 hosted in ImgBB

  • #2
    Giorgio, help graph bar should be what you need, particularly the use of over() option.

    Comment


    • #3
      To add another variable on top, you will need twoway bar. If you want to add an arrow, you will need twoway bar.

      Comment


      • #4
        Thank you both Nick Cox x and Fei Wang.For a panel do I have to collapse first in mean or will twoway bar be possible to do that?
        I mean I have a panel of countries, some variables with data for each year and for each country and if they belong to a particular group as shown in the picture above. Will twoway bar be able to create this, or I have to collapse in mean (by missing information) in order to create it?

        Comment


        • #5
          Giorgio, now I understand your data structure -- a country-level panel data. It would be helpful to futher introduce the meaning of the vertical axis and the current form of its corresponding variable in the panel data.

          Comment


          • #6
            Originally posted by Fei Wang View Post
            Giorgio, now I understand your data structure -- a country-level panel data. It would be helpful to futher introduce the meaning of the vertical axis and the current form of its corresponding variable in the panel data.
            I am having some free stata format data from IMF data that can be found here https://data.imf.org/api/document/download?key=61362330.

            Countries are classified by income and region.

            I would like to reproduce the graph in #1 for countries and for the FD variable in the data according to their classification and by decade 1980-1989, 1990-1999, 2000-2009 and 2010-2019

            In addition to that, I would like to add two other same type graphs with a second y line at the right with a second variable that I have produced as part of my project (not present in those data). My first, second y is an indicator that is allowed to receive negative values. The second y variable for the third graph is a categorical dummy variable form 1-15. Thank you very much in advance for any help you can provide..

            Comment


            • #7
              Fei Wang I am aware that there is the dataex command, but for convenience and the size of the data I attach the IMF dta here
              Attached Files

              Comment


              • #8
                Sorry, but #7 is quite the wrong way round. Whose convenience is served by ignoring our requests, which are based on long experience of what works well in general? Please use dataex.

                Comment


                • #9
                  Originally posted by Fei Wang View Post
                  Giorgio, now I understand your data structure -- a country-level panel data. It would be helpful to futher introduce the meaning of the vertical axis and the current form of its corresponding variable in the panel data.

                  Fei Wang and Nick Cox

                  Here below are some of my data . I am having some data from IMF for a panel data for countries. Countries are classified by income and region.

                  Where index1 index2a index2b are quality indexes I have produced,
                  ka is the index in the figure #1
                  cat1 and cat2 are categorical dummies
                  and d1 and d2 are dummy variables.


                  I would like to reproduce the graph in #1 for countries and for the ka variable in the data according to their classification, by income and regions. First as total and then by decade 1980-1989, 1990-1999, 2000-2009 and 2010-2019.


                  In addition to that, I would like to add some other same type graphs with a second y line at the right with a second variable

                  -A tab graph for ka and index1 as second y r according to their classification, by income and regions. First as total and then by decade 1980-1989, 1990-1999, 2000-2009 and 2010-2019. In each decade should appear total for that decade and then by their classification, income and regions

                  -A tab graph for ka andindex2a index2b as second y according to their classification, by income and regions. First as total and then by decade 1980-1989, 1990-1999, 2000-2009 and 2010-2019. In each decade should appear total for that decade and then their classification, income and regions

                  -A tab graph for ka and​​​​​​​ categorical as second y according to their classification, by income and regions. First as total and then by decade 1980-1989, 1990-1999, 2000-2009 and 2010-2019. In each decade should appear total for that decade and then by their classification, income and regions

                  -A tab graph for ka and​​​​​​​ d1 and d2 as second y according to their classification, by income and regions. First as total and then by decade 1980-1989, 1990-1999, 2000-2009 and 2010-2019. In each decade should appear total for that decade and then by their classification, income and regions


                  In the data sample below I have included only four countries from my dataset, Two counties for each income classification as indicatives.

                  Thank you very much in advance for any help you can provide.

                  Best

                  ​​​​​​​Giorgio




                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input float id str97 country str28(imf_income imf_region) float(index1 index2a index2b ka) byte(cat1 cat2) float(d1 d2)
                  1 "Australia"   "AM" "Asia and Pacific"        8.6         0        1  .8800636  4 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"  2.7697804         0        1  .9400318  4 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"       -4.5         0        1         1  4 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"       -4.5         0        1         1  4 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"  18.228453         0        1  .9400318  4 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"     22.593         0        1  .8800636  4 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"    27.6381         0        1  .8200954  4 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"     48.458         0        1  .7601272  1 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"     31.889         0        1   .700159  1 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"   29.87246         0        1   .700159  1 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"      5.674         0        1   .700159  1 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"      5.674         0        1   .700159  1 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"  -6.130934  .2967033 .7032967   .700159  1 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"    -34.113         1        0   .700159  1 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"    -34.113         1        0  .7601272  1 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific" -17.802141  .7142857 .2857143  .8200954  1 4 1 0
                  1 "Australia"   "AM" "Asia and Pacific"     22.975         0        1  .8800636  1 4 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         0        1 .16434518  8 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         0        1 .16434518  8 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         0        1 .16434518  8 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         0        1 .16434518  8 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         1        0 .16434518  7 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         1        0 .16434518  7 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0 .21153846 .7884616 .16434518  7 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0  .4917582 .5082418 .16434518  7 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         1        0 .16434518  8 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         1        0 .16434518  8 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         1        0 .16434518  8 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          0         1        0 .16434518 10 3 1 0
                  2 "India"       "EM" "Asia and Pacific"          .         .        . .16434518 10 3 1 0
                  2 "India"       "EM" "Asia and Pacific"          .         .        . .16434518 10 3 1 0
                  2 "India"       "EM" "Asia and Pacific"          .         .        . .16434518 10 3 1 0
                  2 "India"       "EM" "Asia and Pacific"          .         .        . .16434518  8 2 1 0
                  2 "India"       "EM" "Asia and Pacific"          .         .        . .16434518  8 2 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"     -9.788         0        1  .8800636 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific" -14.278473         0        1  .9400318 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"    -21.986         0        1         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"    -21.986         0        1         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"  -6.882123         0        1         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"     -7.235         0        1         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"     -7.235 .33516484 .6648352         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"  -8.191456         1        0         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"    -29.707         1        0         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"    -29.707         1        0         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific" -21.978655         1        0         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"     37.456         1        0         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"     37.456         1        0         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"  35.647743         1        0         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"     -1.262         1        0         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"     -1.262         1        0         1 12 3 1 0
                  3 "New Zealand" "AM" "Asia and Pacific"  -2.527769         1        0         1 12 3 1 0
                  4 "Turkey"      "EM" "Europe"                  6.5         0        1 .16434518 14 5 0 1
                  4 "Turkey"      "EM" "Europe"             6.464286         0        1 .16434518 14 5 0 1
                  4 "Turkey"      "EM" "Europe"                  5.2         0        1 .16434518 14 5 0 1
                  4 "Turkey"      "EM" "Europe"                  5.2         0        1 .41687185 14 5 0 1
                  4 "Turkey"      "EM" "Europe"            29.073414 .49041095  .509589 .16434518 14 5 1 0
                  4 "Turkey"      "EM" "Europe"            31.695776         0        1 .16434518 14 5 1 0
                  4 "Turkey"      "EM" "Europe"               29.936         0        1 .16434518 10 3 1 0
                  4 "Turkey"      "EM" "Europe"            14.872792  .3763736 .6236264 .16434518 10 3 1 0
                  4 "Turkey"      "EM" "Europe"                5.187         0        1 .16434518 13 4 1 0
                  4 "Turkey"      "EM" "Europe"                5.187         0        1 .16434518 13 4 1 0
                  4 "Turkey"      "EM" "Europe"                    .         .        .  .4476323 13 4 1 0
                  4 "Turkey"      "EM" "Europe"                    .         .        .  .4476323 13 4 1 0
                  4 "Turkey"      "EM" "Europe"                    .         .        .  .4476323 12 3 1 0
                  4 "Turkey"      "EM" "Europe"                    .         .        .  .4476323 12 3 1 0
                  4 "Turkey"      "EM" "Europe"                    .         .        .  .4476323 12 3 1 0
                  4 "Turkey"      "EM" "Europe"                    .         .        .  .4476323 12 3 1 0
                  4 "Turkey"      "EM" "Europe"                    .         .        .  .4476323 12 3 1 0
                  end

                  Comment

                  Working...
                  X