Announcement

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

  • two graphs in once

    Hey there,

    I'd like to show two graphs in one diagram but so far I wasn't successful with it. That's why I hope to find some help here:

    This is my do-File
    Code:
    import excel "/Users/nicolasstappen/Desktop/Nico/Studium/Master/5. Semester/Masterarbeit/Daten/tESTall Data in one file nur ab 2019_MN.xlsx", sheet("FDI Flows") firstrow case(lower)
    
    codebook
    
    drop indicator // no information and/or variation
    drop measure // no information and/or variation
    
    replace location="belgium" if location=="BEL"
    replace location="france" if location=="FRA"
    replace location="germany" if location=="DEU"
    replace location="ireland" if location=="IRL"
    replace location="italy" if location=="ITA"
    replace location="netherlands" if location=="NLD"
    replace location="poland" if location=="POL"
    replace location="spain" if location=="ESP"
    replace location="sweden" if location=="SWE"
    replace location="united kingdom" if location=="GBR"
    
    rename location partner
    
    //gen fdibalance = inwardvalueus - outwardvalueus FDI Balance nicht sinnvoll
    
    gen periodq_new=.
    
    xtset inwardvalueus
    xtset outwardvalueus
    
    gen zeit = yq(floor(period/100), mod(period, 100))
    format zeit %tq
    sort partner
    sort zeit
    
    format %30.0g inwardvalueus // um e's wegzubekommen
    format %30.0g outwardvalueus // um e's wegzubekommen
    
    graph twoway line inwardvalueus zeit if partner=="netherlands", title("Netherlands FDI inward") name(graph1) xline(240.33) xline(721) xlabel(, angle(45)) ylabel(, angle(45)) c(L) //Graph
    graph twoway line outwardvalueus zeit if partner=="netherlands", title("Netherlands FDI outward") name(graph2) xline(240.33) xline(721) xlabel(, angle(45)) ylabel(, angle(45)) c(L) //Graph
    
    
    graph twoway line inwardvalueus zeit if partner=="poland", title("Poland FDI inward") name(graph1) xline(240.33) xline(721) xlabel(, angle(45)) ylabel(, angle(45)) c(L) //Graph
    graph twoway line outwardvalueus zeit if partner=="poland", title("Poland FDI outward") name(graph2) xline(240.33) xline(721) xlabel(, angle(45)) ylabel(, angle(45)) c(L) //Graph
    
    
    graph combine graph1 graph2
    
    //graph drop graph1 //only show combined graph
    //graph drop graph2 //only show combined graph
    //

    and this is the data
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str14 partner str7 time double(inwardvalueus outwardvalueus) long period float(periodq_new zeit)
    "france"         "2019-Q1"  15801.803711618  31005.848044239 201901 . 236
    "united kingdom" "2019-Q1" -5248.8514548239  5749.1066870852 201901 . 236
    "sweden"         "2019-Q1"  6274.7067968147   9128.163368902 201901 . 236
    "belgium"        "2019-Q1" -13358.334266204  3931.4899809694 201901 . 236
    "italy"          "2019-Q1"  4238.4887495802  6441.9164894212 201901 . 236
    "OECD"           "2019-Q1"  161328.33199881  260177.28759616 201901 . 236
    "ireland"        "2019-Q1" -1615.3587820441  10237.322288145 201901 . 236
    "spain"          "2019-Q1"  10454.494570693  7427.5159520878 201901 . 236
    "netherlands"    "2019-Q1"  1060.6029922758  14281.245577074 201901 . 236
    "poland"         "2019-Q1"  8275.1273432293  298.14889759828 201901 . 236
    "germany"        "2019-Q1"  21841.688122691  64563.536325982 201901 . 236
    "germany"        "2019-Q2"   17217.91671331  30454.296428971 201902 . 237
    "france"         "2019-Q2"  9812.3035724145  13524.958811153 201902 . 237
    "poland"         "2019-Q2"  2724.8959096057  3074.4905899026 201902 . 237
    "united kingdom" "2019-Q2"  30228.432873915  6011.9959162838 201902 . 237
    "OECD"           "2019-Q2"  167210.92761196  88136.030856549 201902 . 237
    "netherlands"    "2019-Q2"   15892.15304489 -18394.200941453 201902 . 237
    "spain"          "2019-Q2" -1505.6531960148  8230.1578417105 201902 . 237
    "italy"          "2019-Q2" -2039.1884025523 -1491.0668308519 201902 . 237
    "sweden"         "2019-Q2"   1932.973064436  7106.9914021933 201902 . 237
    "ireland"        "2019-Q2" -8768.6107690585 -66854.360237322 201902 . 237
    "belgium"        "2019-Q2" -30671.666853241   -34518.0790328 201902 . 237
    "belgium"        "2019-Q3"  12730.325758424  11978.058882794 201903 . 238
    "sweden"         "2019-Q3"   139.8068930509  3610.9730432851 201903 . 238
    "united kingdom" "2019-Q3"  27280.500255232 -3924.1960183767 201903 . 238
    "germany"        "2019-Q3"  784.25612896004 -3397.4129631703 201903 . 238
    "spain"          "2019-Q3"  6084.1822456062  8319.7134221426 201903 . 238
    "OECD"           "2019-Q3"  196668.96868467  173865.04992055 201903 . 238
    "italy"          "2019-Q3"  10735.159520878  9612.7952535542 201903 . 238
    "netherlands"    "2019-Q3"  -49262.03094705 -5601.4465946491 201903 . 238
    "poland"         "2019-Q3"  3713.9714929105 -645.33067664269 201903 . 238
    "ireland"        "2019-Q3"  33316.914810254  31458.636516288 201903 . 238
    "france"         "2019-Q3"  -1082.783268639   9696.656737914 201903 . 238
    "germany"        "2019-Q4"  12819.928355536  45668.536885705 201904 . 239
    "italy"          "2019-Q4"  5210.9448113736  5222.4605395724 201904 . 239
    "united kingdom" "2019-Q4" -6814.7013782542 -13916.539050536 201904 . 239
    "sweden"         "2019-Q4"  763.12143740945 -3747.2900517137 201904 . 239
    "netherlands"    "2019-Q4"  15533.625856935  23392.128023061 201904 . 239
    "belgium"        "2019-Q4"    22093.3616926  9304.8248068958 201904 . 239
    "poland"         "2019-Q4" -1387.6984952679  -1053.367475083 201904 . 239
    "OECD"           "2019-Q4"  251559.59730321  217603.84313251 201904 . 239
    "ireland"        "2019-Q4"  135556.92376581  59600.358222322 201904 . 239
    "spain"          "2019-Q4"  2384.4173290048   848.5391245942 201904 . 239
    "france"         "2019-Q4" -11431.524926804 -10415.651577658 201904 . 239
    "ireland"        "2020-Q1"  36471.794871795 -22270.085470085 202001 . 240
    "germany"        "2020-Q1"  10991.588603989  30822.231339031 202001 . 240
    "poland"         "2020-Q1"  7228.4598819524  474.10527303831 202001 . 240
    "france"         "2020-Q1" -4006.4979046969  27735.283869423 202001 . 240
    "netherlands"    "2020-Q1" -33671.979148718  -13675.39791339 202001 . 240
    "spain"          "2020-Q1"  7933.9031339031  15716.239316239 202001 . 240
    "italy"          "2020-Q1"  3470.1732193732  5837.8313390313 202001 . 240
    "sweden"         "2020-Q1"  21298.739372618  24592.114835445 202001 . 240
    "belgium"        "2020-Q1"  5030.1994301994  10177.777777778 202001 . 240
    "OECD"           "2020-Q1"  126824.30365918  159758.07507214 202001 . 240
    "united kingdom" "2020-Q1"  16261.382583045 -25543.157624727 202001 . 240
    "netherlands"    "2020-Q2" -30057.836422792  3391.7362381766 202002 . 241
    "ireland"        "2020-Q2"  57092.877492877 -11680.911680912 202002 . 241
    "france"         "2020-Q2"  1600.0318889956 -11504.263278447 202002 . 241
    "OECD"           "2020-Q2"  133861.55233407  189172.04818954 202002 . 241
    "sweden"         "2020-Q2" -1134.5646437995 -207.17287208052 202002 . 241
    "italy"          "2020-Q2" -8091.4472934473 -4257.2603988604 202002 . 241
    "germany"        "2020-Q2"  9176.4888888889 -6550.7111111111 202002 . 241
    "united kingdom" "2020-Q2" -18092.856226754  -23026.80518148 202002 . 241
    "spain"          "2020-Q2"  9136.1823361823  12279.202279202 202002 . 241
    "belgium"        "2020-Q2" -20452.421652422 -16949.287749288 202002 . 241
    "poland"         "2020-Q2"  2422.0255640694  259.20150164959 202002 . 241
    "germany"        "2020-Q3"  3767.9384615385 -9424.9424501425 202003 . 242
    "netherlands"    "2020-Q3" -6003.0078951567 -13559.703062108 202003 . 242
    "sweden"         "2020-Q3"  4047.7974309695  1717.2112012335 202003 . 242
    "belgium"        "2020-Q3"  14547.008547009  11095.156695157 202003 . 242
    "italy"          "2020-Q3" -6424.4968660969  4147.4928774929 202003 . 242
    "OECD"           "2020-Q3"  25018.894871969  123404.23978418 202003 . 242
    "spain"          "2020-Q3"   2434.188034188  10297.435897436 202003 . 242
    "poland"         "2020-Q3"  2717.9468821734  126.86127669565 202003 . 242
    "ireland"        "2020-Q3" -21614.814814815 -30309.971509972 202003 . 242
    "france"         "2020-Q3"  2713.7502709096  4053.2715817896 202003 . 242
    "united kingdom" "2020-Q3"  9637.0398871361  8115.9420289855 202003 . 242
    "ireland"        "2020-Q4"   10172.07977208  17780.056980057 202004 . 243
    "spain"          "2020-Q4" -6896.8660968661  -3351.566951567 202004 . 243
    "united kingdom" "2020-Q4"  10395.023727075 -24933.948954726 202004 . 243
    "germany"        "2020-Q4"   40506.47977208   45639.78005698 202004 . 243
    "sweden"         "2020-Q4" -5085.0733465802 -2103.9773282517 202004 . 243
    "OECD"           "2020-Q4"   140081.2008905 -96059.128517324 202004 . 243
    "poland"         "2020-Q4"  1281.3203971068  243.92514911976 202004 . 243
    "netherlands"    "2020-Q4" -35020.811521368 -165515.39843533 202004 . 243
    "france"         "2020-Q4"  1842.0480402749 -11855.857090063 202004 . 243
    "italy"          "2020-Q4" -12522.545868946 -7579.8427350427 202004 . 243
    "belgium"        "2020-Q4"  14755.555555556  7422.2222222222 202004 . 243
    "OECD"           "2021-Q1"  238976.30644668  363100.69388938 202101 . 244
    "belgium"        "2021-Q1"  6323.3207190161  18412.961210974 202101 . 244
    "italy"          "2021-Q1"  2821.4995269631  4716.1270104068 202101 . 244
    "united kingdom" "2021-Q1"  4291.6093535076  18429.160935351 202101 . 244
    "ireland"        "2021-Q1" -8587.9848628193   18372.75307474 202101 . 244
    "germany"        "2021-Q1"  8736.5361873226  46582.134578997 202101 . 244
    "netherlands"    "2021-Q1" -16337.064291627  14184.458890728 202101 . 244
    "spain"          "2021-Q1"  6453.4058656575  4586.0927152318 202101 . 244
    "france"         "2021-Q1"  25385.501814107  23865.156705922 202101 . 244
    "poland"         "2021-Q1"  9535.1622976288   362.0725286629 202101 . 244
    "sweden"         "2021-Q1"  7698.1193671373  3524.2336974898 202101 . 244
    "poland"         "2021-Q2"  3885.5754603706  1041.1954886023 202102 . 245
    end
    format %tq zeit

    at the moment I have the charts this way: I try to find a way to get netherlands FDI inward and outward in once and for Poland the same
    Click image for larger version

Name:	Bildschirmfoto 2022-11-12 um 08.41.30.png
Views:	1
Size:	715.0 KB
ID:	1689102
    Thanks in advance
    Nico

  • #2
    Code:
    #delimit ;
    graph twoway (line inwardvalueus zeit if partner=="netherlands", c(L)) || 
                (line outwardvalueus zeit if partner=="netherlands", c(L)) ,
                xline(240.33)
                xlabel(, angle(45)) 
                ylabel(, angle(45))
                legend(label(1 "Inwards") label(2 "Outwards") ring(0) pos(8) col(1))
                title("Netherlands FDI") 
                scheme(s2color)
                name(netherlands, replace)
                ;
    #delimit cr
    which produces:
    Click image for larger version

Name:	Screenshot 2022-11-12 at 1.47.05 PM.png
Views:	1
Size:	694.9 KB
ID:	1689107

    Comment


    • #3
      Hey Hemanshu Kumar
      thanks again for your help
      in the poland graph the label (inwards and outwards) hides the graph. Do you know how to place it under the graph?

      Comment


      • #4
        Sure, just remove the positioning arguments in the legend() option, and leave it at:

        Code:
            legend(label(1 "Inwards") label(2 "Outwards"))

        Comment

        Working...
        X