Announcement

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

  • Create separate bar graph by group

    Hi,

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str25 Country byte rec_ind double(count_CAR count RX1_CAR RX1 q_car_s)
    "Australia"       0  23   0    .8560080396683416                    . 1
    "Australia"       0  79   0   .16237847698733573                    . 5
    "Australia"       1  36   0    .4250850153574481                    . 1
    "Australia"       1  36   0    .5555438245126342                    . 5
    "Austria"         0  54   0    .4359371659209928                    . 1
    "Austria"         0   2 107    2.756748549877308    .0404185606701987 5
    "Austria"         1  40   0    .6204551718541174                    . 1
    "Belgium"         0   8   0   1.0937295636830435                    . 1
    "Belgium"         0   4  20    .4101477454989122  -.26850798926990826 5
    "Belgium"         1  11   0    .4243018831708977                    . 1
    "Belgium"         1   8  17    -1.77708959146885   2.5203684968178908 5
    "Canada"          0  17 103   -.5387415654363457   .13089198080613404 1
    "Canada"          0   1   0    .7553460701221565                    . 5
    "Canada"          1  47  34    -.128663137795674  -.34173149777515316 1
    "Canada"          1   5   0    1.172731105630623                    . 5
    "Chile"           0  18  39    .7282302211544985   -.3405421762109744 1
    "Chile"           0  26   0    -.656098923468159                    . 5
    "Chile"           1  15   0   -.9950696454908995                    . 5
    "Czech Republic"  0  68   0 .0019549427999252522                    . 1
    "Czech Republic"  0   9   0  -1.0688964671329613                    . 5
    "Czech Republic"  1  15  24   .24682236902235624   1.1437674458829148 1
    "Czech Republic"  1  10   0 -.017218638300646738                    . 5
    "Denmark"         0  38   0   -.2147344895251305                    . 1
    "Denmark"         0  20 137    1.155983037709821   .40467548318740665 5
    "Denmark"         1  18   0   -.4861648065529407                    . 1
    "Denmark"         1  17 138   1.1814482601692455   .08795097002229092 5
    "Estonia"         0  11   0   -.7267796006495075                    . 1
    "Estonia"         1   5   0    .9739916288367123                    . 1
    "Euro"            0  36  90   -.3764596553506073   .05769281872121804 1
    "Euro"            0   3   0   -1.670387941638692                    . 5
    "Euro"            1  27  43   -1.320470202984637    .4480339301959048 1
    "Finland"         0   9   0   -1.744895447811986                    . 1
    "Finland"         1   9   0   -.2839702049507774                    . 1
    "France"          0   2  29   1.9296341689619578  -.09978845138831167 1
    "France"          0   7   0   .19346379470923974                    . 5
    "France"          1   6  18   .44485447515700455   .08532687619728424 1
    "France"          1  12   0   -1.304349946738039                    . 5
    "Germany"         0 120 112  -.07167036747227613 -.012110659483352366 1
    "Germany"         1  65  92    .5958964990633756    .0714807870757614 1
    "Greece"          0   6  22   -.4580865720799003   -.8350565654854752 5
    "Greece"          1   5  24   2.4478415548923316   .15352392591250577 5
    "Hungary"         0  68   0   1.0176218930281737                    . 5
    "Hungary"         1  54   4   1.0035618380400257    1.592920467059522 5
    "Iceland"         0  82 103    .7038124941344155    .5873176128329171 5
    "Iceland"         1   1   0   -6.672557549310376                    . 1
    "Iceland"         1  24  34  -1.7037388852627473  -1.4419252935057107 5
    "Ireland"         0   1   0  -.43685023860704497                    . 1
    "Ireland"         0  16   0  -.17135759720467011                    . 5
    "Ireland"         1   5  11   -.9679632897937894    .8081802642077333 1
    "Ireland"         1  21   0   -.6915148272943215                    . 5
    "Israel"          0   7   0   -.9230899235042183                    . 1
    "Israel"          1   2   0    2.830301198599139                    . 1
    "Italy"           0  83  50   .28483046245605875    .7168096496513247 5
    "Italy"           1  76  41  -.14321151617892924    .3507077167672786 5
    "Japan"           0 208  95  -.22808261864690935  -.04568401549520885 1
    "Japan"           1 179  42  -.09426309089120459   -.3501849052823263 1
    "Korea"           0   4   0    .4380762376662295                    . 1
    "Korea"           1  13   0  -3.3614147886334598                    . 1
    "Mexico"          0  62   0    .9732092183691566                    . 5
    "Mexico"          1  47   0    .2833453004246696                    . 5
    "Netherlands"     0  63  25    -.734819938634958   -.9594594126709174 1
    "Netherlands"     1  56  22  -.13831721661622273   .07269277828452715 1
    "New Zealand"     0  22   0    .9701569210775979                    . 1
    "New Zealand"     0  89  69    .7698823421563551    .6607780453287401 5
    "New Zealand"     1  34   0    .5020465003047245                    . 1
    "New Zealand"     1  56  59   .21174850569024944   .07166741910755452 5
    "Norway"          0  21   0    .6744256535915303                    . 1
    "Norway"          0  30   0   .39561360342082647                    . 5
    "Norway"          1   4   0   -2.388401884181068                    . 1
    "Norway"          1  12   0   -.6401907656175877                    . 5
    "Poland"          0  26   0   1.9900105664712586                    . 1
    "Poland"          0  54 130   .18400682989200026    .4433061952391079 5
    "Poland"          1   7   0   -.4547604192605185                    . 1
    "Poland"          1  51  75      .86090660441212    .2224595130806299 5
    "Slovak Republic" 0  22   0    .8190512177030669                    . 1
    "Slovak Republic" 0  11  34   1.6428624838420647     .806307446375401 5
    "Slovak Republic" 1   6   0     .474004304523216                    . 1
    "Slovak Republic" 1   5   2   2.5163960340006764   1.5407300287345826 5
    "Spain"           0  89   0    .7605498214901566                    . 5
    "Spain"           1   1  15    6.292016608824902    .2626943776423296 1
    "Spain"           1  81   0   .06869696713126909                    . 5
    "Sweden"          0  41   0   -.5615677156981833                    . 1
    "Sweden"          0  20 102     .592753627287389   .36883496593176424 5
    "Sweden"          1  14   0   -.5738620350983904                    . 1
    "Sweden"          1  28 102   .37984819685527116   -.2890351553378149 5
    "Switzerland"     0 266 174  -.10015251373360526 -.024266033786217125 1
    "Switzerland"     1 181 135  -.10265602126272859  -.10344676421824094 1
    "Turkey"          0 135  81    .9620007149470955    1.332166531693338 5
    "Turkey"          1  70  48    .7655310928896678    .8920596469667608 5
    "United Kingdom"  0   5   0   -1.036431261809917                    . 1
    "United Kingdom"  0  19  42    .5284919345478942   .33710217389863983 5
    "United Kingdom"  1   3   0  -2.1158354294380453                    . 1
    "United Kingdom"  1  18   6    1.019817670911835   1.3432802799599688 5
    "Austria"         1   .  83                    .   -.3886052881246376 .
    "Chile"           1   .  28                    .   -.9217085255569936 .
    "Estonia"         0   .  39                    .   -.6402750183759985 .
    "Estonia"         1   .  16                    .    .2913987640134702 .
    "Finland"         0   .   1                    .   -5.982408232743608 .
    "Portugal"        1   .  14                    .    .1171713563745109 .
    "Spain"           0   .   8                    .   -.8920188621372116 .
    end

    I am trying to create separate bar graph for each "Country" by group (rec_ind -> recession indicator 0 or 1 and q_car_s -> long short portfolios 5 or 1) : 4 total

    I would like the bar graph to compare number of occurrence of each country in the portfolio: "Count_CAR" and "Count" . In other words, these count would be the length of the horizontal bars.
    I would also like to put a return tag on or inside each country bar: "RX1_CAR" and "RX1"

    I would like the 4 graphs to look like that (enclosed) but with a return tag that is not included in the picture.

    I have tried the following, but I could not figure out how to output the 4 graphs and the various specifications above.
    Code:
    graph bar
    If possible, I would like to have the option to display only the top 10 countries there too.
    Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	209.5 KB
ID:	1590801


    Can someone help? Thanks a lot in advance




  • #2
    I don't follow quite what you want but here are some suggestions.

    Your sample graph (using what? and with a puzzling chessboard backdrop...) shows two horizontal bars for each of several countries.

    Code:
    graph hbar (asis) count_CAR count , over(Country, sort(1) descending) by(rec_ind q_car_s) nofill
    The result is a mess and adding a return tag (I don't understand what "tag" means here or how you want return shown -- its units are quite different) wouldn't make it less messy

    Still, this may get you moving.

    Comment


    • #3
      Thanks a lot Nick, this is what I wanted! To make it more clear, I will only keep the G10 currencies:

      Code:
      keep if inlist(Country,"New Zealand","United Kingdom","Australia", "Switzerland", "Japan", "Euro", "Norway", "Sweden", "Canada")
      I would like to display RX1_CAR and CAR, which is the weighted average return of each of these currencies based on their portfolio occurrence (count_CAR and count, respectively). How can I show that? Thanks.

      Comment

      Working...
      X