Announcement

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

  • Twoway bar by groups and time periods

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

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


    I would like to reproduce the graph in the image 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.



    Click image for larger version

Name:	Screen-Shot-2021-10-27-at-22-07-29.png
Views:	4
Size:	84.9 KB
ID:	1634810



    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 ts) str28(imf_region imf_income) str97 country float(ka index1 index2a index2b) byte(cat1 cat2) float(d1 d2)
    1 1986 "Asia and Pacific" "AM" "Australia"    .8800636        8.6         0        1  4 4 1 0
    1 1987 "Asia and Pacific" "AM" "Australia"    .9400318  2.7697804         0        1  4 4 1 0
    1 1988 "Asia and Pacific" "AM" "Australia"           1       -4.5         0        1  4 4 1 0
    1 1989 "Asia and Pacific" "AM" "Australia"           1       -4.5         0        1  4 4 1 0
    1 1996 "Asia and Pacific" "AM" "Australia"    .9400318  18.228453         0        1  4 4 1 0
    1 1997 "Asia and Pacific" "AM" "Australia"    .8800636     22.593         0        1  4 4 1 0
    1 1998 "Asia and Pacific" "AM" "Australia"    .8200954    27.6381         0        1  4 4 1 0
    1 1999 "Asia and Pacific" "AM" "Australia"    .7601272     48.458         0        1  1 4 1 0
    1 2006 "Asia and Pacific" "AM" "Australia"     .700159     31.889         0        1  1 4 1 0
    1 2007 "Asia and Pacific" "AM" "Australia"     .700159   29.87246         0        1  1 4 1 0
    1 2008 "Asia and Pacific" "AM" "Australia"     .700159      5.674         0        1  1 4 1 0
    1 2009 "Asia and Pacific" "AM" "Australia"     .700159      5.674         0        1  1 4 1 0
    1 2010 "Asia and Pacific" "AM" "Australia"     .700159  -6.130934  .2967033 .7032967  1 4 1 0
    1 2011 "Asia and Pacific" "AM" "Australia"     .700159    -34.113         1        0  1 4 1 0
    1 2012 "Asia and Pacific" "AM" "Australia"    .7601272    -34.113         1        0  1 4 1 0
    1 2013 "Asia and Pacific" "AM" "Australia"    .8200954 -17.802141  .7142857 .2857143  1 4 1 0
    1 2014 "Asia and Pacific" "AM" "Australia"    .8800636     22.975         0        1  1 4 1 0
    2 1986 "Asia and Pacific" "EM" "India"       .16434518          0         0        1  8 2 1 0
    2 1987 "Asia and Pacific" "EM" "India"       .16434518          0         0        1  8 2 1 0
    2 1988 "Asia and Pacific" "EM" "India"       .16434518          0         0        1  8 2 1 0
    2 1989 "Asia and Pacific" "EM" "India"       .16434518          0         0        1  8 2 1 0
    2 1996 "Asia and Pacific" "EM" "India"       .16434518          0         1        0  7 2 1 0
    2 1997 "Asia and Pacific" "EM" "India"       .16434518          0         1        0  7 2 1 0
    2 1998 "Asia and Pacific" "EM" "India"       .16434518          0 .21153846 .7884616  7 2 1 0
    2 1999 "Asia and Pacific" "EM" "India"       .16434518          0  .4917582 .5082418  7 2 1 0
    2 2006 "Asia and Pacific" "EM" "India"       .16434518          0         1        0  8 2 1 0
    2 2007 "Asia and Pacific" "EM" "India"       .16434518          0         1        0  8 2 1 0
    2 2008 "Asia and Pacific" "EM" "India"       .16434518          0         1        0  8 2 1 0
    2 2009 "Asia and Pacific" "EM" "India"       .16434518          0         1        0 10 3 1 0
    2 2010 "Asia and Pacific" "EM" "India"       .16434518          .         .        . 10 3 1 0
    2 2011 "Asia and Pacific" "EM" "India"       .16434518          .         .        . 10 3 1 0
    2 2012 "Asia and Pacific" "EM" "India"       .16434518          .         .        . 10 3 1 0
    2 2013 "Asia and Pacific" "EM" "India"       .16434518          .         .        .  8 2 1 0
    2 2014 "Asia and Pacific" "EM" "India"       .16434518          .         .        .  8 2 1 0
    3 1986 "Asia and Pacific" "AM" "New Zealand"  .8800636     -9.788         0        1 12 3 1 0
    3 1987 "Asia and Pacific" "AM" "New Zealand"  .9400318 -14.278473         0        1 12 3 1 0
    3 1988 "Asia and Pacific" "AM" "New Zealand"         1    -21.986         0        1 12 3 1 0
    3 1989 "Asia and Pacific" "AM" "New Zealand"         1    -21.986         0        1 12 3 1 0
    3 1996 "Asia and Pacific" "AM" "New Zealand"         1  -6.882123         0        1 12 3 1 0
    3 1997 "Asia and Pacific" "AM" "New Zealand"         1     -7.235         0        1 12 3 1 0
    3 1998 "Asia and Pacific" "AM" "New Zealand"         1     -7.235 .33516484 .6648352 12 3 1 0
    3 1999 "Asia and Pacific" "AM" "New Zealand"         1  -8.191456         1        0 12 3 1 0
    3 2006 "Asia and Pacific" "AM" "New Zealand"         1    -29.707         1        0 12 3 1 0
    3 2007 "Asia and Pacific" "AM" "New Zealand"         1    -29.707         1        0 12 3 1 0
    3 2008 "Asia and Pacific" "AM" "New Zealand"         1 -21.978655         1        0 12 3 1 0
    3 2009 "Asia and Pacific" "AM" "New Zealand"         1     37.456         1        0 12 3 1 0
    3 2010 "Asia and Pacific" "AM" "New Zealand"         1     37.456         1        0 12 3 1 0
    3 2011 "Asia and Pacific" "AM" "New Zealand"         1  35.647743         1        0 12 3 1 0
    3 2012 "Asia and Pacific" "AM" "New Zealand"         1     -1.262         1        0 12 3 1 0
    3 2013 "Asia and Pacific" "AM" "New Zealand"         1     -1.262         1        0 12 3 1 0
    3 2014 "Asia and Pacific" "AM" "New Zealand"         1  -2.527769         1        0 12 3 1 0
    4 1986 "Europe"           "EM" "Turkey"      .16434518        6.5         0        1 14 5 0 1
    4 1987 "Europe"           "EM" "Turkey"      .16434518   6.464286         0        1 14 5 0 1
    4 1988 "Europe"           "EM" "Turkey"      .16434518        5.2         0        1 14 5 0 1
    4 1989 "Europe"           "EM" "Turkey"      .41687185        5.2         0        1 14 5 0 1
    4 1996 "Europe"           "EM" "Turkey"      .16434518  29.073414 .49041095  .509589 14 5 1 0
    4 1997 "Europe"           "EM" "Turkey"      .16434518  31.695776         0        1 14 5 1 0
    4 1998 "Europe"           "EM" "Turkey"      .16434518     29.936         0        1 10 3 1 0
    4 1999 "Europe"           "EM" "Turkey"      .16434518  14.872792  .3763736 .6236264 10 3 1 0
    4 2006 "Europe"           "EM" "Turkey"      .16434518      5.187         0        1 13 4 1 0
    4 2007 "Europe"           "EM" "Turkey"      .16434518      5.187         0        1 13 4 1 0
    4 2008 "Europe"           "EM" "Turkey"       .4476323          .         .        . 13 4 1 0
    4 2009 "Europe"           "EM" "Turkey"       .4476323          .         .        . 13 4 1 0
    4 2010 "Europe"           "EM" "Turkey"       .4476323          .         .        . 12 3 1 0
    4 2011 "Europe"           "EM" "Turkey"       .4476323          .         .        . 12 3 1 0
    4 2012 "Europe"           "EM" "Turkey"       .4476323          .         .        . 12 3 1 0
    4 2013 "Europe"           "EM" "Turkey"       .4476323          .         .        . 12 3 1 0
    4 2014 "Europe"           "EM" "Turkey"       .4476323          .         .        . 12 3 1 0
    end



  • #2
    [QUOTE=Giorgio Di Stefano;n1634809]Hello
    I am having some data from IMF for a panel data for countries. Countries are classified by income and region. I provide a sample of my data below

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


    I would like to reproduce the graph in the image 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.



    [ATTACH=CONFIG]n1634810[/ATTACH]


    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 ts) str28(imf_region imf_income) str97 country float(ka index1 index2a index2b) byte(cat1 cat2) float(d1 d2)
    1 1986 "Asia and Pacific" "AM" "Australia" .8800636 8.6 0 1 4 4 1 0
    1 1987 "Asia and Pacific" "AM" "Australia" .9400318 2.7697804 0 1 4 4 1 0
    1 1988 "Asia and Pacific" "AM" "Australia" 1 -4.5 0 1 4 4 1 0
    1 1989 "Asia and Pacific" "AM" "Australia" 1 -4.5 0 1 4 4 1 0
    1 1996 "Asia and Pacific" "AM" "Australia" .9400318 18.228453 0 1 4 4 1 0
    1 1997 "Asia and Pacific" "AM" "Australia" .8800636 22.593 0 1 4 4 1 0
    1 1998 "Asia and Pacific" "AM" "Australia" .8200954 27.6381 0 1 4 4 1 0
    1 1999 "Asia and Pacific" "AM" "Australia" .7601272 48.458 0 1 1 4 1 0
    1 2006 "Asia and Pacific" "AM" "Australia" .700159 31.889 0 1 1 4 1 0
    1 2007 "Asia and Pacific" "AM" "Australia" .700159 29.87246 0 1 1 4 1 0
    1 2008 "Asia and Pacific" "AM" "Australia" .700159 5.674 0 1 1 4 1 0
    1 2009 "Asia and Pacific" "AM" "Australia" .700159 5.674 0 1 1 4 1 0
    1 2010 "Asia and Pacific" "AM" "Australia" .700159 -6.130934 .2967033 .7032967 1 4 1 0
    1 2011 "Asia and Pacific" "AM" "Australia" .700159 -34.113 1 0 1 4 1 0
    1 2012 "Asia and Pacific" "AM" "Australia" .7601272 -34.113 1 0 1 4 1 0
    1 2013 "Asia and Pacific" "AM" "Australia" .8200954 -17.802141 .7142857 .2857143 1 4 1 0
    1 2014 "Asia and Pacific" "AM" "Australia" .8800636 22.975 0 1 1 4 1 0
    2 1986 "Asia and Pacific" "EM" "India" .16434518 0 0 1 8 2 1 0
    2 1987 "Asia and Pacific" "EM" "India" .16434518 0 0 1 8 2 1 0
    2 1988 "Asia and Pacific" "EM" "India" .16434518 0 0 1 8 2 1 0
    2 1989 "Asia and Pacific" "EM" "India" .16434518 0 0 1 8 2 1 0
    2 1996 "Asia and Pacific" "EM" "India" .16434518 0 1 0 7 2 1 0
    2 1997 "Asia and Pacific" "EM" "India" .16434518 0 1 0 7 2 1 0
    2 1998 "Asia and Pacific" "EM" "India" .16434518 0 .21153846 .7884616 7 2 1 0
    2 1999 "Asia and Pacific" "EM" "India" .16434518 0 .4917582 .5082418 7 2 1 0
    2 2006 "Asia and Pacific" "EM" "India" .16434518 0 1 0 8 2 1 0
    2 2007 "Asia and Pacific" "EM" "India" .16434518 0 1 0 8 2 1 0
    2 2008 "Asia and Pacific" "EM" "India" .16434518 0 1 0 8 2 1 0
    2 2009 "Asia and Pacific" "EM" "India" .16434518 0 1 0 10 3 1 0
    2 2010 "Asia and Pacific" "EM" "India" .16434518 . . . 10 3 1 0
    2 2011 "Asia and Pacific" "EM" "India" .16434518 . . . 10 3 1 0
    2 2012 "Asia and Pacific" "EM" "India" .16434518 . . . 10 3 1 0
    2 2013 "Asia and Pacific" "EM" "India" .16434518 . . . 8 2 1 0
    2 2014 "Asia and Pacific" "EM" "India" .16434518 . . . 8 2 1 0
    3 1986 "Asia and Pacific" "AM" "New Zealand" .8800636 -9.788 0 1 12 3 1 0
    3 1987 "Asia and Pacific" "AM" "New Zealand" .9400318 -14.278473 0 1 12 3 1 0
    3 1988 "Asia and Pacific" "AM" "New Zealand" 1 -21.986 0 1 12 3 1 0
    3 1989 "Asia and Pacific" "AM" "New Zealand" 1 -21.986 0 1 12 3 1 0
    3 1996 "Asia and Pacific" "AM" "New Zealand" 1 -6.882123 0 1 12 3 1 0
    3 1997 "Asia and Pacific" "AM" "New Zealand" 1 -7.235 0 1 12 3 1 0
    3 1998 "Asia and Pacific" "AM" "New Zealand" 1 -7.235 .33516484 .6648352 12 3 1 0
    3 1999 "Asia and Pacific" "AM" "New Zealand" 1 -8.191456 1 0 12 3 1 0
    3 2006 "Asia and Pacific" "AM" "New Zealand" 1 -29.707 1 0 12 3 1 0
    3 2007 "Asia and Pacific" "AM" "New Zealand" 1 -29.707 1 0 12 3 1 0
    3 2008 "Asia and Pacific" "AM" "New Zealand" 1 -21.978655 1 0 12 3 1 0
    3 2009 "Asia and Pacific" "AM" "New Zealand" 1 37.456 1 0 12 3 1 0
    3 2010 "Asia and Pacific" "AM" "New Zealand" 1 37.456 1 0 12 3 1 0
    3 2011 "Asia and Pacific" "AM" "New Zealand" 1 35.647743 1 0 12 3 1 0
    3 2012 "Asia and Pacific" "AM" "New Zealand" 1 -1.262 1 0 12 3 1 0
    3 2013 "Asia and Pacific" "AM" "New Zealand" 1 -1.262 1 0 12 3 1 0
    3 2014 "Asia and Pacific" "AM" "New Zealand" 1 -2.527769 1 0 12 3 1 0
    4 1986 "Europe" "EM" "Turkey" .16434518 6.5 0 1 14 5 0 1
    4 1987 "Europe" "EM" "Turkey" .16434518 6.464286 0 1 14 5 0 1
    4 1988 "Europe" "EM" "Turkey" .16434518 5.2 0 1 14 5 0 1
    4 1989 "Europe" "EM" "Turkey" .41687185 5.2 0 1 14 5 0 1
    4 1996 "Europe" "EM" "Turkey" .16434518 29.073414 .49041095 .509589 14 5 1 0
    4 1997 "Europe" "EM" "Turkey" .16434518 31.695776 0 1 14 5 1 0
    4 1998 "Europe" "EM" "Turkey" .16434518 29.936 0 1 10 3 1 0
    4 1999 "Europe" "EM" "Turkey" .16434518 14.872792 .3763736 .6236264 10 3 1 0
    4 2006 "Europe" "EM" "Turkey" .16434518 5.187 0 1 13 4 1 0
    4 2007 "Europe" "EM" "Turkey" .16434518 5.187 0 1 13 4 1 0
    4 2008 "Europe" "EM" "Turkey" .4476323 . . . 13 4 1 0
    4 2009 "Europe" "EM" "Turkey" .4476323 . . . 13 4 1 0
    4 2010 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0
    4 2011 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0
    4 2012 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0
    4 2013 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0
    4 2014 "Europe" "EM" "Turkey" .4476323 . . . 12 3 1 0
    end

    Comment


    • #3



      I have been trying to solve by my own but I think I have created a mess, I run this code , unsuccessfully




      Code:
      recode  ts (1980/1989 =1)(1990/1999=2)(2000/2009 =3)(2010/2020=4), gen(decades)
      
      
      recode  ts (1980/1989 =1), gen(decades1980)
       label variable decades1980 "1980-1989"
       
       
      recode  ts (1990/1999=2), gen(decades1990)
       label variable decades1990 "1990-1999"
       
        recode  ts (2000/2009 =3) , gen(decades2000)
       label variable decades2000 "2000-2010"
       
       
        recode  ts (2010/2020 =4) , gen(decades2010)
       label variable decades2010 "2010-2020"
       
       
      
      
      
      bysort imf_income : egen kaavg=mean(kaopen)
      
      
      bysort imf_income : egen mean_index1=mean(index1)
      
      
      
      
      twoway bar mean_index1 kaavg, over(imf_income)  by (decades)


      Could anyone please kindly be of help?

      Comment


      • #4
        Not entirely sure what you need, but this might be a starting point:

        Code:
        recode  ts (1980/1989 =1 "1980/1989")(1990/1999=2 "1990/1999")(2000/2009 =3 "2000/2009 ")(2010/2020=4 "2010/2020"), gen(decades)
        
        graph bar (mean) ka, over(imf_region) asyvar over(decades)
        Click image for larger version

Name:	example.png
Views:	1
Size:	67.0 KB
ID:	1635551

        Comment


        • #5
          Originally posted by alejoforero View Post
          Not entirely sure what you need, but this might be a starting point:

          Code:
          recode ts (1980/1989 =1 "1980/1989")(1990/1999=2 "1990/1999")(2000/2009 =3 "2000/2009 ")(2010/2020=4 "2010/2020"), gen(decades)
          
          graph bar (mean) ka, over(imf_region) asyvar over(decades)
          [ATTACH=CONFIG]n1635551[/ATTACH]

          Thank you so much. I would also need 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


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

          Best

          Giorgio

          Comment

          Working...
          X