Announcement

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

  • vertical line graph two way

    Dear all

    1) I'd like to put a vertical line on the x-axis in my Stata Graph. I need this line to show when the Brexit occured (31.January.2020) to better describe the development before and after Brexit.
    2) Furthermore I'd like to show my y-axis values in a 45° angle because they have to many digits. I know I can switch it in the "Graph-Editor" settings, but does anybody know if there is a appropriate command for it, so I can put it in my Do-File?

    This is my Do-File so far
    Code:
    *Data import*
    
    
    import excel "/Users/nicolasstappen/Desktop/Nico/Studium/Master/5. Semester/Masterarbeit/Daten/tESTall Data in one file nur ab 2019_MN.xlsx", sheet("Trade values") firstrow case(lower)
    
    ** Exceltabelle mit Daten bis August22:
    //import excel "/Users/nicolasstappen/Desktop/Nico/Studium/Master/5. Semester/Masterarbeit/Daten/tESTall Data in one file nur ab 2019.xlsx", sheet("Trade values") firstrow case(lower)
    
    
    codebook // entweder nur codebook oder codebook varname
    
    drop classification // no information and/or variation
    drop perioddesc // no info that is not within Period already
    drop reportercode // no information and/or variation
    drop partnercode // no added information
    drop tradeflowcode // no added information
    
    replace tradeflow="export" if tradeflow=="Export"
    replace tradeflow="import" if tradeflow=="Import"
    replace tradeflow="reimport" if tradeflow=="Re-import"
    
    replace reporter="united kingdom" if reporter=="United Kingdom"
    
    replace partner = lower(partner)
    
    gen period_new=.
    
    xtset tradevalueus
    xtset tradevaluemilus
    
    gen zeit = ym(floor(period/100), mod(period, 100)) 
    format zeit %tmNN/CCYY
    sort partner
    sort zeit
    **sort period_new
    
    format %100.0g tradevalueus // um e's wegzubekommen
    format %100.0g tradevaluemilus // um e's wegzubekommen
    
    replace tradevalueus=round(tradevalueus,1)
    
    graph twoway line tradevaluemilus zeit if tradeflow=="export" & partner=="germany", title("Germany Export") name(graph1) c(L) //Graph
    graph twoway line tradevaluemilus zeit if tradeflow=="import" & partner=="germany", title("Germany Import") name(graph2) c(L) //Graph
    
    graph combine graph1 graph2
    
    graph twoway line tradevaluemilus zeit if tradeflow=="export" & partner=="germany", title("Germany Export") name(graph1) c(L) //Graph
    graph twoway line tradevaluemilus zeit if tradeflow=="import" & partner=="germany", title("Germany Import") name(graph2) c(L) //Graph
    
    graph combine graph1 graph2
    
    graph drop graph1
    graph drop graph2

    Thanks in advance and best regards

    Nico

  • #2
    Please pose an extract of your data using the dataex command, if you want us to be able to help you optimally.

    But for your specific queries, you should look at the option xline for twoway commands
    Code:
    help added_line_options
    , and the angle() suboption to the ylabel() option for the same command
    Code:
    help axis_label_options

    Comment


    • #3
      Thanks for your help I tried it, but if I use this command:
      Code:
      graph twoway line tradevaluemilus zeit if tradeflow=="export" & partner=="germany", title("Germany Export") name(graph1) xline(01/2020) c(L) //Graph
      the graph looks like that:
      Click image for larger version

Name:	Bildschirmfoto 2022-11-04 um 10.43.23.png
Views:	1
Size:	510.8 KB
ID:	1687984


      and the combined graph:
      Click image for larger version

Name:	Bildschirmfoto 2022-11-04 um 10.43.13.png
Views:	1
Size:	1.21 MB
ID:	1687985

      this is the data:

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input int year long period str6 tradeflow str14 reporter str11 partner double(tradevalueus tradevaluemilus) float(period_new zeit)
      2019 201901 "import" "united kingdom" "cyprus"        55023353   55.023353 . 708
      2019 201901 "import" "united kingdom" "france"      3345632873 3345.632873 . 708
      2019 201901 "export" "united kingdom" "sweden"       699555933  699.555933 . 708
      2019 201901 "export" "united kingdom" "ireland"     2252081222 2252.081222 . 708
      2019 201901 "import" "united kingdom" "netherlands" 4882920070  4882.92007 . 708
      2019 201901 "import" "united kingdom" "poland"      1296655241 1296.655241 . 708
      2019 201901 "import" "united kingdom" "belgium"     2815327697 2815.327697 . 708
      2019 201901 "import" "united kingdom" "sweden"       798252211  798.252211 . 708
      2019 201901 "export" "united kingdom" "belgium"     1495376569 1495.376569 . 708
      2019 201901 "export" "united kingdom" "france"      2912525852 2912.525852 . 708
      2019 201901 "import" "united kingdom" "ireland"     1484422049 1484.422049 . 708
      2019 201901 "export" "united kingdom" "poland"       669251204  669.251204 . 708
      2019 201901 "export" "united kingdom" "cyprus"        81315282   81.315282 . 708
      2019 201901 "import" "united kingdom" "germany"     7486553110  7486.55311 . 708
      2019 201901 "import" "united kingdom" "italy"       2063738095 2063.738095 . 708
      2019 201901 "export" "united kingdom" "spain"       1094456027 1094.456027 . 708
      2019 201901 "export" "united kingdom" "germany"     4394305322 4394.305322 . 708
      2019 201901 "import" "united kingdom" "spain"       1743338234 1743.338234 . 708
      2019 201901 "export" "united kingdom" "netherlands" 2769554117 2769.554117 . 708
      2019 201901 "export" "united kingdom" "italy"       1132099622 1132.099622 . 708
      2019 201902 "export" "united kingdom" "poland"       649200306  649.200306 . 709
      2019 201902 "import" "united kingdom" "poland"      1281665853 1281.665853 . 709
      2019 201902 "export" "united kingdom" "spain"       1272303422 1272.303422 . 709
      2019 201902 "import" "united kingdom" "sweden"       741905239  741.905239 . 709
      2019 201902 "import" "united kingdom" "france"      3501860847 3501.860847 . 709
      2019 201902 "import" "united kingdom" "spain"       1984694688 1984.694688 . 709
      2019 201902 "export" "united kingdom" "cyprus"        37631849   37.631849 . 709
      2019 201902 "import" "united kingdom" "belgium"     3037358635 3037.358635 . 709
      2019 201902 "import" "united kingdom" "italy"       2235127433 2235.127433 . 709
      2019 201902 "export" "united kingdom" "italy"       1126102613 1126.102613 . 709
      2019 201902 "export" "united kingdom" "germany"     4213456381 4213.456381 . 709
      2019 201902 "export" "united kingdom" "ireland"     2150430471 2150.430471 . 709
      2019 201902 "import" "united kingdom" "cyprus"        18091336   18.091336 . 709
      2019 201902 "export" "united kingdom" "france"      2742392593 2742.392593 . 709
      2019 201902 "export" "united kingdom" "netherlands" 2677100612 2677.100612 . 709
      2019 201902 "export" "united kingdom" "belgium"     1486437485 1486.437485 . 709
      2019 201902 "export" "united kingdom" "sweden"       548185506  548.185506 . 709
      2019 201902 "import" "united kingdom" "germany"     7790603649 7790.603649 . 709
      2019 201902 "import" "united kingdom" "ireland"     1478323398 1478.323398 . 709
      2019 201902 "import" "united kingdom" "netherlands" 4838710101 4838.710101 . 709
      2019 201903 "import" "united kingdom" "italy"       2577322765 2577.322765 . 710
      2019 201903 "export" "united kingdom" "sweden"       588674632  588.674632 . 710
      2019 201903 "import" "united kingdom" "netherlands" 6184150925 6184.150925 . 710
      2019 201903 "export" "united kingdom" "ireland"     3039984867 3039.984867 . 710
      2019 201903 "export" "united kingdom" "cyprus"        47666764   47.666764 . 710
      2019 201903 "import" "united kingdom" "spain"       2192812954 2192.812954 . 710
      2019 201903 "export" "united kingdom" "poland"       638470361  638.470361 . 710
      2019 201903 "export" "united kingdom" "italy"       1277829953 1277.829953 . 710
      2019 201903 "import" "united kingdom" "france"      4541394138 4541.394138 . 710
      2019 201903 "import" "united kingdom" "germany"     9069188183 9069.188183 . 710
      2019 201903 "export" "united kingdom" "spain"       1295101764 1295.101764 . 710
      2019 201903 "export" "united kingdom" "germany"     4511701103 4511.701103 . 710
      2019 201903 "import" "united kingdom" "belgium"     3466473794 3466.473794 . 710
      2019 201903 "import" "united kingdom" "ireland"     1563695732 1563.695732 . 710
      2019 201903 "import" "united kingdom" "poland"      1300207200   1300.2072 . 710
      2019 201903 "export" "united kingdom" "belgium"     1703458073 1703.458073 . 710
      2019 201903 "import" "united kingdom" "cyprus"        18611451   18.611451 . 710
      2019 201903 "export" "united kingdom" "netherlands" 2997322683 2997.322683 . 710
      2019 201903 "export" "united kingdom" "france"      3666527094 3666.527094 . 710
      2019 201903 "import" "united kingdom" "sweden"       754609064  754.609064 . 710
      2019 201904 "export" "united kingdom" "belgium"     1283133284 1283.133284 . 711
      2019 201904 "import" "united kingdom" "poland"      1078206373 1078.206373 . 711
      2019 201904 "import" "united kingdom" "cyprus"        22077650    22.07765 . 711
      2019 201904 "import" "united kingdom" "italy"       2063780664 2063.780664 . 711
      2019 201904 "import" "united kingdom" "sweden"       671991091  671.991091 . 711
      2019 201904 "export" "united kingdom" "netherlands" 2141048260  2141.04826 . 711
      2019 201904 "export" "united kingdom" "poland"       526802599  526.802599 . 711
      2019 201904 "import" "united kingdom" "germany"     7189949830  7189.94983 . 711
      2019 201904 "import" "united kingdom" "netherlands" 3817665403 3817.665403 . 711
      2019 201904 "import" "united kingdom" "ireland"     1528379568 1528.379568 . 711
      2019 201904 "export" "united kingdom" "spain"        999322661  999.322661 . 711
      2019 201904 "import" "united kingdom" "spain"       1639046457 1639.046457 . 711
      2019 201904 "export" "united kingdom" "italy"       1055387005 1055.387005 . 711
      2019 201904 "export" "united kingdom" "germany"     3314833594 3314.833594 . 711
      2019 201904 "export" "united kingdom" "sweden"       495588089  495.588089 . 711
      2019 201904 "export" "united kingdom" "france"      2345920150  2345.92015 . 711
      2019 201904 "import" "united kingdom" "france"      2874816687 2874.816687 . 711
      2019 201904 "import" "united kingdom" "belgium"     2403264479 2403.264479 . 711
      2019 201904 "export" "united kingdom" "ireland"     2204298084 2204.298084 . 711
      2019 201904 "export" "united kingdom" "cyprus"        43432022   43.432022 . 711
      2019 201905 "import" "united kingdom" "germany"     6931577040  6931.57704 . 712
      2019 201905 "import" "united kingdom" "sweden"       644083371  644.083371 . 712
      2019 201905 "import" "united kingdom" "belgium"     2315620808 2315.620808 . 712
      2019 201905 "export" "united kingdom" "france"      2406632222 2406.632222 . 712
      2019 201905 "export" "united kingdom" "spain"       1159021385 1159.021385 . 712
      2019 201905 "import" "united kingdom" "italy"       2193522941 2193.522941 . 712
      2019 201905 "export" "united kingdom" "ireland"     2202216967 2202.216967 . 712
      2019 201905 "export" "united kingdom" "cyprus"        49228473   49.228473 . 712
      2019 201905 "import" "united kingdom" "ireland"     1530409338 1530.409338 . 712
      2019 201905 "export" "united kingdom" "poland"       645541193  645.541193 . 712
      2019 201905 "export" "united kingdom" "belgium"     1587587247 1587.587247 . 712
      2019 201905 "import" "united kingdom" "france"      2945024844 2945.024844 . 712
      2019 201905 "import" "united kingdom" "netherlands" 3810667750  3810.66775 . 712
      2019 201905 "import" "united kingdom" "cyprus"        18241300     18.2413 . 712
      2019 201905 "export" "united kingdom" "italy"       1069105731 1069.105731 . 712
      2019 201905 "export" "united kingdom" "sweden"       530739415  530.739415 . 712
      2019 201905 "import" "united kingdom" "poland"      1100839579 1100.839579 . 712
      2019 201905 "import" "united kingdom" "spain"       1794119905 1794.119905 . 712
      2019 201905 "export" "united kingdom" "netherlands" 2766853440  2766.85344 . 712
      2019 201905 "export" "united kingdom" "germany"     3915718074 3915.718074 . 712
      end
      format %tmNN/CCYY zeit
      thank you for your help

      Comment


      • #4
        Nico Stappen when you specify xline(01/2020), Stata has no way of knowing you mean January 2020. It thinks you are specifying a numlist of integers from 1 through 2020 (1,2,3,4.... 2020). Your x-axis is actually monthly numbers, where 1 is Jan 1960, 2 is Feb 1960, and so on. So it is trying to draw a vertical line for every month from Jan 1960 to 1960+(2020/12) = sometime in the year 2128. The way to specify January 2020 would be
        Code:
        xline(tm(2020m1))
        using the tm() function to conveniently convert human-readable monthly dates into Stata's internal numeric monthly format.

        Comment


        • #5
          Thanks a lot Hemanshu Kumar,
          I got the red vertical line with this command
          Code:
          graph twoway line tradevaluemilus zeit if tradeflow=="export" & partner=="germany", title("Germany Export") name(graph1) xline(721) c(L) //Graph
          721 is according to your explanations January 2020 and it looks the way I want it to look

          Click image for larger version

Name:	Bildschirmfoto 2022-11-04 um 13.04.26.png
Views:	1
Size:	791.8 KB
ID:	1688025

          Comment


          • #6
            When I try the same with another data set with quarterly data then Stata doesn't show a red line into the graph. Do you know why?

            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=="belgium", title("Belgium FDI inward") name(graph1) xline(721) c(L) //Graph
            graph twoway line outwardvalueus zeit if partner=="belgium", title("Belgium FDI outward") name(graph2) xline(721) c(L) //Graph
            
            
            //
            graph combine graph1 graph2
            
            graph drop graph1 //only show combined graph
            graph drop graph2 //only show combined graph
            //

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

            Thanks in advance
            Nico

            Comment


            • #7
              Originally posted by Nico Stappen View Post
              721 is according to your explanations January 2020 and it looks the way I want it to look
              No, it's actually 720.
              Code:
              . dis tm(2020m1)
              720
              That's why the line is slightly off -- it's being drawn for February 2020.

              In your example in #6 you use quarterly dates, so the conversion between numbers and dates changes. 721 would now be (721/4) = over 180 years after the start of 1960. What you need is xline(tq(2020q1)) or alternatively xline(240)

              Code:
              . dis tq(2020q1)
              240

              Comment


              • #8
                yes sure, you are right. I said it a little bit confusing. I need the line at the end of january 20, so beginning of febuary 20 which is 721 I think. The event on this Date I want to show with the red line is the Brexit.

                As well your quarterly advice worked for me. I took 240.33 for the red line at the End of January 2020 in the quarterly graph. Thank you so much!!

                One last question: Is there any command so that the two graphs do not look so compressed (see picture) when Stata shows them in a single window?

                Click image for larger version

Name:	Bildschirmfoto 2022-11-04 um 19.49.50.png
Views:	1
Size:	768.6 KB
ID:	1688123

                Comment


                • #9
                  Why not show both exports and imports on the same graph?

                  Comment


                  • #10
                    A good idea as well, but how can I do this? Thought it was easier to show them in one window

                    Comment


                    • #11
                      Something like this?
                      Code:
                      graph twoway line tradevaluemilus zeit if tradeflow=="export" & partner=="germany" || ///
                                line tradevaluemilus zeit if tradeflow=="import" & partner=="germany", title("Germany Exports and Imports") ///
                               name(graph) xline(721) c(L) legend(label(1 "Exports") label(2 "Imports"))
                      Last edited by Hemanshu Kumar; 04 Nov 2022, 14:00.

                      Comment


                      • #12
                        Hey Hemanshu Kumar
                        thanks so much for your help Looks very nice now.

                        For my other dataset I want to try it as well, but so far I didn't make it, so the graph is still compressed.

                        This is the code so far
                        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 not appropriate
                        
                        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=="belgium", title("Belgium 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=="belgium", title("Belgium 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
                        //
                        
                        save "/Users/nicolasstappen/Desktop/Nico/Studium/Master/5. Semester/Masterarbeit/Do-File", replace
                        
                        *Teilanalyse FDI

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

                        thanks in advance
                        nico

                        Comment


                        • #13
                          Originally posted by Hemanshu Kumar View Post

                          No, it's actually 720.
                          Code:
                          . dis tm(2020m1)
                          720
                          That's why the line is slightly off -- it's being drawn for February 2020.

                          In your example in #6 you use quarterly dates, so the conversion between numbers and dates changes. 721 would now be (721/4) = over 180 years after the start of 1960. What you need is xline(tq(2020q1)) or alternatively xline(240)

                          Code:
                          . dis tq(2020q1)
                          240
                          Hey Hemanshu Kumar,

                          hope you can help me again. I extended my data a little bit. Instead of starting in January 2019 I start in June 2017 with the data. I've already put them into my excel sheet, which I import with stata. Furthermore I changed 720 to 690 in this command
                          Code:
                          graph twoway line tradevaluemilus zeit if tradeflow=="export" & partner=="germany" || ///
                                    line tradevaluemilus zeit if tradeflow=="import" & partner=="germany", title("Germany") ///
                                   name(graph1) xline(690) c(L) legend(label(1 "Exports from UK to Germany") label(2 "Imports from Germany to UK")) // both graphs in one picture
                          Nevertheless Stata shows only the graph from January 2019. Do you know why the graph doesn't start in June 2017?

                          Comment


                          • #14
                            This is my do-file:

                            Code:
                            ***ANALYSIS HUBI THESIS***
                            
                            *Data import*
                            
                            **Datamanipulation Imports/Exports
                            
                            import excel "/Users/nicolasstappen/Desktop/Nico/Studium/Master/5. Semester/Masterarbeit/Daten/vollständige Daten 29.11.xlsx", sheet("Trade values") firstrow case(lower)
                            
                            ** import excel "/Users/nicolasstappen/Desktop/Nico/Studium/Master/5. Semester/Masterarbeit/Daten/tESTall Data in one file nur ab 2019_MN.xlsx", sheet("Trade values") firstrow case(lower)
                            
                            ** Excel with data until august22:
                            //import excel "/Users/nicolasstappen/Desktop/Nico/Studium/Master/5. Semester/Masterarbeit/Daten/tESTall Data in one file nur ab 2019.xlsx", sheet("Trade values") firstrow case(lower)
                            
                            
                            codebook // codebook or codebook varname
                            
                            drop classification // no information and/or variation
                            drop perioddesc // no info that is not within Period already
                            drop reportercode // no information and/or variation
                            drop partnercode // no added information
                            drop tradeflowcode // no added information
                            
                            replace tradeflow="export" if tradeflow=="Export"
                            replace tradeflow="import" if tradeflow=="Import"
                            replace tradeflow="reimport" if tradeflow=="Re-import"
                            
                            replace reporter="united kingdom" if reporter=="United Kingdom"
                            
                            replace partner = lower(partner)
                            
                            xtset tradevalueus
                            xtset tradevaluemilus
                            
                            gen zeit = ym(floor(period/100), mod(period, 100)) 
                            format zeit %tmNN/CCYY
                            
                            gen month = month(dofm(zeit))
                            
                            sort partner
                            sort zeit
                            
                            format %30.0g tradevalueus // drop e's in Data Editor
                            format %30.0g tradevaluemilus // drop e's in Data Editor
                            
                            replace tradevalueus=round(tradevalueus,1)
                            
                            
                            graph twoway line tradevaluemilus zeit if tradeflow=="export" & partner=="germany" || ///
                                      line tradevaluemilus zeit if tradeflow=="import" & partner=="germany", title("Germany") ///
                                     name(graph1) xline(690) c(L) legend(label(1 "Exports from UK to Germany") label(2 "Imports from Germany to UK")) // both graphs in one picture

                            Comment


                            • #15
                              Hemanshu Kumar I think it is because of this command:
                              Code:
                                
                               gen zeit = ym(floor(period/100), mod(period, 100))  format zeit %tmNN/CCYY  gen month = month(dofm(zeit))

                              Could you tell me how to change this to get data from June 2017?

                              sorry for posting that much, got that suspect, while trying to find a solution for it
                              Last edited by Nico Stappen; 29 Nov 2022, 03:56.

                              Comment

                              Working...
                              X