Announcement

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

  • Twoway area of specific quantiles over time (negative and positive values across and within data range)

    Hey together,

    I am replicating some parts of a paper in the GaR literature. I successfully ran the quantile regressions and stored the predicted values in each new variable, respectively (each variable reflects a certain quantile y_q over time). The problem is that the data on the y-axis range both in positive and negative values (also, there are some quantile, which have both positive and negative values). This is the code

    Code:
    twoway area y_q5 y_q10 y_q25 yq50 y_q75 y_q90 y_q95 date, xtitle("") xlabel(,format(%tdCY)) title("One quarter ahead")
    which delivers

    Click image for larger version

Name:	graph_base.png
Views:	1
Size:	168.4 KB
ID:	1646516


    When I add the "nodropbase"-command to the code, I receive the following:

    Click image for larger version

Name:	graph_nodropbase.png
Views:	1
Size:	297.6 KB
ID:	1646517


    This still looks not like the graph I try to replicate. I am fully aware that it must have something to do with the base-command. I tried to follow https://www.statalist.org/forums/for...-cyclic-series, but I am not sure if this is the right procedure.

    Can anyone help me?


    Best,
    Mario

  • #2

    Code:
    twoway line y_q5 y_q10 y_q25 yq50 y_q75 y_q90 y_q95 date
    would seem a simpler starting-point. I guess the graph is a mess because each area is superimposed on the previous ones. You may need something more like
    Code:
     local call  local q = 5  foreach Q in 10 25 50 75 90 95 {      local call `call' || rarea y_q`q' y_q`Q' date      local q = `Q'  }  twoway area q5 date `call', xtitle("") xlabel(,format(%tdCY)) title("One quarter ahead")

    Comment


    • #3
      Thanks for your answer, Nick! Meanwhile, I also found out the rarea-command (note that I abbreviated yt_1_hat_q to y_q before):

      Code:
      twoway rarea yt_1_hat_q5 yt_1_hat_q10 date, color(gs14) lwidth(none) ///
      || rarea yt_1_hat_q10 yt_1_hat_q25 date, color(gs13) lwidth(none) ///
      || rarea yt_1_hat_q25 yt_1_hat_q50 date, color(gs12) lwidth(none) ///
      || rarea yt_1_hat_q50 yt_1_hat_q75 date, color(gs12) lwidth(none) ///
      || rarea yt_1_hat_q75 yt_1_hat_q90 date, color(gs13) lwidth(none) ///
      || rarea yt_1_hat_q90 yt_1_hat_q95 date, color(gs14) lwidth(none) ///
      || line yt_1_hat_q50 date, color(black) lwidth(vthin) ///
      || line yt date, color(blue) lwidth(vthin) lpattern(dash) ///
      xtitle("") xlabel(,format(%tdCY)) ytitle("") title("One quarter ahead") legend(off)
      which gives:
      Click image for larger version

Name:	graph_blueline.jpg
Views:	1
Size:	400.5 KB
ID:	1646550




      Your solution with the loop is, indeed, smarter!

      Still, I have the following problem now: The blue line shall indicate the "realized" yt (here GDP growth). However, the predicted quantiles are forecasts, thus one quarter ahead (t+1). My time variable and the forecasts are "on the same line" (sharing the same observation), although the predictions should be one observation ahead. How can I deal with this issue?

      This is my dataset:
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float yt_1 int date float(nfci yt yt_1_hat_q5 yt_1_hat_q10 yt_1_hat_q25 yt_1_hat_q50 yt_1_hat_q75 yt_1_hat_q90 yt_1_hat_q95)
       4.6  4749  .46 10.2    .2378811   .2451288    .9427513  3.1036425  5.748794  9.187079  9.392401
      -2.2  4839  .91  4.6   -3.225495 -1.8097605   -.5270985   1.907231  3.967443  6.935189  7.376833
       3.8  4930 1.67 -2.2   -7.969353  -4.705585  -2.7102084  .22917153 1.6601585 4.2501054  4.935333
      -3.3  5022 1.79  3.8    -5.77636  -3.633375  -2.2583144   .8759049 3.1621454  6.801996  7.111718
       1.1  5114  .71 -3.3   -6.007069 -3.1427226  -1.0437658        1.1 2.0181882  3.565494  4.510084
      -3.8  5204 2.64  1.1   -9.041839   -5.81153  -4.1475496  -.3686586  1.875816  5.862553  6.157639
      -1.6  5295 4.24 -3.8  -15.112778  -9.872156   -7.683221  -2.687863 -.4973978 4.1709037  4.427767
      -4.7  5387 2.57 -1.6   -9.988355  -6.264012   -4.321063  -.6428117 1.2107263 4.7105045  5.177817
       3.1  5479  .94 -4.7   -7.169085  -3.876843  -1.6303557   .6769589 1.4935074  3.029675 4.0094795
       6.8  5569 -.29  3.1   -.8246291   .1167908   1.5418782   2.979656  4.382001  6.026838       6.8
       5.5  5660  -.5  6.8   1.2435696   1.310694    2.350182   3.678036       5.5  7.534874  8.134158
       9.3  5752 -.25  5.5  .072732836  .56068057    1.737555  3.2467875  4.988198  7.045746  7.670331
       3.1  5844 -.81  9.3    3.064736   2.432711   3.2098405   4.327234  6.368921  8.514969  9.030912
       2.1  5935 -.75  3.1    .3348515   .9796264    2.399739   3.464861 4.6926203  5.920536  6.787129
         3  6026 -.84  2.1   .14579542   .9322258    2.454967  3.4309075 4.4895573  5.479044   6.42244
       4.7  6118  -.8    3     .419291  1.0517913    2.481723   3.504712       4.7  5.866912  6.749514
       8.1  6210 -.88  4.7   1.3279883  1.5694172     2.82236     3.8082  5.202542  6.563603  7.362966
       7.3  6300 -.62  8.1   2.0867271   1.816863     2.72037  3.9721615  5.924018  8.054044  8.601624
         0  6391 -.44  7.3   1.3002886  1.3062584    2.294594   3.679191  5.591403  7.759086  8.316922
       1.4  6483 -.17    0   -2.416426   -.778567    .9689851   2.453538  3.483077   4.75042  5.680627
      16.5  6575 -.11  1.4  -1.9853874  -.5884081   1.0147499   2.570689  3.811932  5.353256  6.189345
         4  6665  .38 16.5    3.059769  1.7573494   1.8014126          4  7.464984  11.81896 11.671842
       5.5  6756  .54    4  -2.5424156   -1.24547    .0953516  2.2201736 4.0589876  6.597269  7.149178
        .8  6848 1.54  5.5   -4.439159  -2.796875   -1.600642  1.3587073  3.779482  7.459401  7.720414
        .5  6940  .83   .8  -4.6043077 -2.4813235   -.8058383  1.5018523  3.018886  5.318068  5.998343
       2.9  7030  .58   .5  -4.0989285  -2.077256   -.3733938  1.7268852   3.10855  5.134086  5.882698
         1  7121 1.36  2.9   -5.066818  -3.021406  -1.5577538  1.2134697 3.2150545  6.324002  6.773733
       1.3  7213 2.16    1   -7.873537  -4.932801   -3.263652   .1247538 2.1735573  5.709559  6.107991
      -7.9  7305 2.22  1.3        -7.9   -4.98048   -3.341763  .10013168 2.2121925  5.849633  6.218321
       -.6  7396 2.79 -7.9   -13.16313  -8.038835   -5.440813 -1.6868403       -.6 2.1109772  2.902294
       7.6  7487  .93  -.6   -5.438644  -2.971599  -1.1499894  1.2159343  2.581989  4.752206  5.494102
       8.5  7579 2.22  7.6   -5.279761 -3.6183176   -2.632295   .9121056  3.874362       8.5       8.5
      -2.9  7671 2.24  8.5   -4.955853 -3.4612374  -2.5682404   1.007006  4.098309  8.883245  8.826513
       4.7  7761 2.32 -2.9   -9.898887   -6.07616  -4.0012326  -.5466635  1.036554   4.10583       4.7
      -4.6  7852  3.1  4.7    -8.70404  -5.895987        -4.6  -.3898783 2.5150075  7.483351  7.474326
      -6.5  7944 2.35 -4.6  -10.681554       -6.5   -4.248624  -.7974114  .5677745 3.3975844 4.0851483
       2.2  8036 1.87 -6.5  -10.261892  -6.010461  -3.5674314 -.53599167  .3906101  2.487343 3.3835924
      -1.4  8126 2.27  2.2   -7.651711  -4.879672   -3.333656  .16338836  2.415882  6.239811  6.545674
        .4  8217 2.84 -1.4  -10.585737  -6.727216   -4.802067   -.901829 1.0811734  4.857038  5.257806
       5.3  8309 1.48   .4   -6.409069  -3.787034  -2.0630784   .7646826 2.4744325       5.3  5.871662
       9.4  8401  .14  5.3   -.9934872 -.21409716    .9877157   2.809641  4.672079  7.051733  7.608809
       8.1  8491 -.14  9.4   1.4175183  1.1975936    1.971609   3.633411  5.942881  8.711869 9.0858755
       8.5  8582 -.11  8.1    .8012161   .8602407   1.7692635   3.434217  5.579636  8.171902  8.615893
       8.2  8674  .02  8.5     .639901   .7028823     1.57187  3.3486476  5.597386   8.37022  8.764399
       7.2  8766 -.14  8.2    .9184253   .9381341   1.8364723   3.478749  5.626277  8.207038  8.651271
         4  8857   .6  7.2   -1.362737  -.6661221    .3438214   2.569317  4.862749  7.957353  8.309804
       3.2  8948  .66    4   -2.844889 -1.4705577  -.12843816  2.0935984 3.9779565     6.625  7.152535
         4  9040 -.03  3.2  -1.4383966  -.3492772   1.0682619   2.718298 4.2328167  6.128992  6.843492
       3.7  9132 -.41    4    -.147836    .536473   1.8670205   3.222227 4.7004848  6.377731  7.122597
       6.4  9222 -.43  3.7  -.22219703   .5091227   1.8705347   3.204658  4.634839  6.246902  7.013386
         3  9313  -.3  6.4    .5730833   .8490617   1.9321535  3.4155235  5.259413  7.412815  7.994885
       3.8  9405  -.3    3    -.841014  .11392652    1.549266  2.9773154   4.36237  5.982458  6.763503
       1.9  9497 -.27  3.8  -.58390355   .2306276   1.5834097   3.048779  4.553181  6.325945   7.05408
       4.1  9587  -.4  1.9  -1.0464551  .06366162    1.611882  2.9410214 4.1396756  5.496586  6.362317
       2.1  9678 -.35  4.1  -.25748155   .4455508    1.766387   3.171828 4.6863527  6.433666  7.160493
       2.8  9770 -.43  2.1   -.8876546  .16317673   1.6903523   2.998442  4.212701  5.573792  6.433912
       4.6  9862 -.42  2.8   -.6217231  .29577076    1.750533  3.0781136 4.3906336  5.870588  6.687711
       3.7  9952  .25  4.6   -1.561892 -.57177883    .7037452  2.6033945  4.413115  6.782668  7.358366
       6.8 10043  .02  3.7  -1.3564715  -.3349556   1.0313231   2.730001  4.330972  6.350893  7.025977
       2.3 10135  .76  6.8   -1.932399 -1.0527252 .0003895685  2.3489964 4.6491723   7.82605  8.169413
       5.4 10227  .21  2.3   -2.417663  -.9940469    .5193297  2.3491514  3.833302   5.80583  6.524253
       2.3 10318  .16  5.4  -1.0023084 -.22999014    .9616788   2.801434 4.6849575  7.098424  7.645585
       5.4 10409  .27  2.3  -2.5688994 -1.1065907    .4074348  2.2858636  3.792786  5.819695  6.525932
       4.1 10501  .12  5.4    -.901484 -.15496096   1.0362754  2.8436255  4.711968  7.089181  7.644466
       3.2 10593   .3  4.1   -1.895878  -.7736734   .55419254  2.4862125 4.2474337  6.583876  7.178679
         3 10683  .39  3.2   -2.497053 -1.1370836    .2849977  2.2752848 3.9492075   6.22605  6.855244
        .9 10774  .19    3   -2.076113   -.805181    .6354578  2.4604666  4.031492  6.095694  6.777214
       4.5 10866  .08   .9   -2.672259 -1.0529048     .604109   2.305836  3.551715  5.186817  6.013576
       1.6 10958  .02  4.5  -1.0237428 -.16198263   1.1214142   2.833109 4.5420413  6.687448  7.315714
        .1 11048 -.04  1.6   -2.078648  -.6764659    .9067286  2.5226305  3.817431  5.453572  6.263738
      -3.4 11139  .04   .1   -2.904163 -1.1508486   .58861446  2.2449198  3.367656  4.841019   5.72272
      -1.9 11231  .37 -3.4   -5.191653  -2.526596  -.42095625  1.4457413 2.2213929  3.444853 4.4643536
       3.1 11323  .13 -1.9    -3.96284 -1.7520967   .19554424   1.892219   2.77921  4.020431  5.000896
       1.9 11413 -.26  3.1   -.9002474   .0605189   1.4859308   2.948012  4.361743  6.033771  6.800839
       1.8 11504 -.47  1.9   -.8700124   .1949627    1.742426   3.014857  4.186944   5.48041  6.360358
       4.8 11596 -.55  1.8   -.7099547   .3233994    1.880358   3.086352  4.214581  5.419853  6.321903
       4.5 11688 -.61  4.8    .6890149   1.084592   2.3300948   3.536294  5.046606  6.668067  7.406738
       3.9 11779 -.76  4.5     .942333  1.3010864    2.576048  3.6558475  5.068744  6.507195   7.29389
       4.1 11870  -.8  3.9    .7936109   1.246386    2.583076  3.6207085  4.937453  6.245536  7.075468
        .8 11962 -.63  4.1    .4482893   .9707551   2.2885633  3.4671705  4.875425   6.36896  7.152658
       2.4 12054 -.83   .8  -.42009485   .6323875     2.28992  3.2528095 4.1398177  4.934454  5.951897
         2 12144  -.9  2.4    .4218054  1.1096345    2.600646  3.5328605  4.609224  5.591387  6.529413
       5.4 12235   -1    2     .507502   1.210721   2.7420924   3.586786 4.5712156       5.4  6.381746
         4 12327 -.91  5.4   1.6947445  1.7770406   2.9571376   3.930063  5.407485  6.851155  7.615647
       5.6 12419 -.89    4   1.0620568   1.436823   2.7621796   3.728528   5.02461  6.266807  7.109167
       2.4 12509 -.68  5.6   1.1981863   1.388866     2.55073   3.713237  5.304943  6.988445  7.694516
       4.6 12600 -.72  2.4 -.031904284   .7720033   2.2649617   3.342998  4.487677  5.632983  6.534449
       1.4 12692  -.5  4.6   .32856545   .8350183   2.1024313    3.39449   4.91956  6.609349  7.337381
       1.4 12784 -.55  1.4   -.8763191  .23691295   1.8353122   3.034798 4.1090465  5.251576  6.177034
       3.5 12874 -.65  1.4   -.6242581   .4244858   2.0218036  3.1402774  4.176573  5.228467  6.174236
       2.9 12965 -.64  3.5    .2239488   .8597826   2.2396438  3.4003875 4.7238765  6.114233  6.935076
       2.7 13057 -.68  2.9   .07522674   .8050821   2.2466722  3.3652484  4.592585  5.852574  6.716654
       7.2 13149  -.7  2.7   .04245668   .7993535   2.2614477   3.360567  4.553323  5.763813   6.64366
       3.7 13240 -.64  7.2   1.7628193  1.6597826   2.6563156   3.877261  5.700071  7.670798  8.275109
       4.3 13331 -.66  3.7    .3575433   .9405406   2.2994652  3.4472604  4.790149   6.19375   7.00695
       3.1 13423 -.68  4.3    .6575021  1.1077849    2.404332   3.545687  4.961956  6.441544  7.223694
       6.2 13515 -.64  3.1   .05758439   .7732961   2.1945982  3.3488336  4.618342  5.945956  6.790207
       5.2 13605 -.61  6.2     1.27129  1.3872945    2.487754  3.7167325  5.415977  7.257038  7.913777
       3.1 13696 -.61  5.2    .8553791  1.1710783   2.3751402   3.587848   5.15214  6.836345  7.551606
         4 13788 -.47  3.1   -.3709193   .4544221    1.877563   3.169519 4.5035477  5.985241  6.794964
      end
      format %td date
      Last edited by Mario Schimmels; 24 Jan 2022, 10:12.

      Comment


      • #4
        twoway supports L. and F. operators.

        Comment

        Working...
        X