Announcement

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

  • Display qdate in a nice way in a two way graph

    Hi,

    Here are my data:
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(qdate aaci_combined_au_avg aaci_temp_high_au_avg aaci_temp_low_au_avg aaci_rainfall_au_avg aaci_sea_level_au_avg aaci_cdd_au_avg aaci_wind_au_avg)
    120 -.08  -.1 -.05  .03 -.15 -.06    .
    121 -.06  -.1 -.05  .05 -.14 -.08    .
    122 -.05  -.1 -.06  .07 -.11 -.09    .
    123 -.05  -.1 -.04  .04 -.09 -.07    .
    124 -.02 -.06 -.04  .06 -.06 -.05    .
    125 -.03 -.09 -.05  .05 -.06 -.05    .
    126 -.01 -.05    0  .04 -.01 -.04    .
    127 -.01 -.05  .03  .03 -.02  .02    .
    128 -.01 -.05  .04  .05 -.02  .02    .
    129 -.01 -.06  .09  .06 -.04  .01    .
    130    0 -.06  .08  .05  .01    0    .
    131 -.01 -.11  .05  .07    0 -.04    .
    132 -.01 -.11  .04  .09 -.01 -.05    .
    133 -.04 -.14  .05  .06 -.04 -.05    .
    134 -.06 -.15  .04  .05 -.08 -.05    .
    135 -.09 -.19  .03  .06 -.15 -.08    .
    136 -.09 -.17  .02  .07 -.17 -.07    .
    137  -.1 -.16 -.01  .01 -.16 -.02    .
    138 -.09 -.13  .02  .01 -.14  .04    .
    139 -.09 -.12 -.02    0 -.15  .07    .
    140 -.09 -.11    0    0 -.17  .06    .
    141 -.12 -.12 -.02 -.03 -.21  .07    .
    142 -.11 -.07 -.02 -.04 -.22   .1    .
    143  -.1 -.07 -.06 -.02 -.22  .09    .
    144 -.12  -.1 -.11 -.03 -.22  .05    .
    145 -.12 -.09 -.12    0 -.26  .02    .
    146 -.13 -.12 -.13    0 -.26  .01    .
    147  -.1  -.1 -.15  .02 -.23 -.06    .
    148 -.09 -.08 -.14  .02 -.21 -.06    .
    149 -.08 -.08 -.15  .01 -.19 -.02    .
    150 -.11 -.08 -.17    0 -.25 -.01    .
    151 -.12 -.06 -.13    0 -.28  .01    .
    152 -.12 -.04  -.1 -.02 -.31  .03    .
    153 -.09  .03  -.1 -.02 -.28  .03    .
    154 -.07  .03 -.11    0 -.25  .02    .
    155 -.05  .05 -.11  .02 -.22  .02    .
    156 -.05  .04 -.08  .01 -.21 -.01    .
    157 -.05  .04 -.06  .03 -.21 -.05    .
    158 -.04  .02 -.04  .02 -.16  -.1    .
    159 -.03  .02 -.01  .04 -.16 -.16    .
    160 -.02  .01 -.03  .05 -.13 -.17    .
    161 -.02  .02 -.02  .06 -.13  -.2    .
    162 -.04 -.03 -.01  .05 -.12 -.22    .
    163 -.03 -.03  .02  .07 -.13 -.19    .
    164 -.02 -.01  .07  .06 -.11 -.17    .
    165 -.01 -.02  .07  .05 -.06 -.16    .
    166    0 -.02  .09  .05 -.04 -.15    .
    167 -.01 -.03   .1  .03 -.03 -.15    .
    168 -.01 -.04   .1  .02    0 -.15    .
    169    0 -.01  .12    0  .02 -.14    .
    170  .03  .03  .14    0  .06  -.1    .
    171  .05  .05  .15 -.02  .13 -.06  .02
    172  .07  .05  .14 -.01  .16 -.03  .02
    173  .06 -.01  .13 -.01  .19 -.05  .01
    174  .06 -.01  .15 -.04  .24 -.04    0
    175  .06    0  .15 -.07  .24    0  .01
    176  .07  .04  .14 -.06  .23  .02  .01
    177  .05  .04  .16 -.08   .2  .04 -.01
    178  .05  .04  .14 -.08  .18  .05  .02
    179  .05  .05  .14 -.08  .18  .07  .03
    180  .05  .05  .15 -.09  .18  .07  .06
    181  .06  .08  .18 -.11   .2  .12  .04
    182  .08  .14  .19 -.09   .2  .13  .06
    183   .1  .16  .19 -.11  .23  .09  .07
    184   .1  .19   .2 -.12  .22  .08   .1
    185   .1  .19  .17 -.11  .22  .06  .09
    186  .07  .18  .15 -.13  .16  .07  .06
    187  .09  .22  .14 -.13  .17  .13  .05
    188  .08  .23  .13 -.13  .13  .16  .05
    189  .09  .23  .12 -.11  .15  .13  .05
    190   .1  .22  .11 -.08  .16  .11  .03
    191  .11   .2  .11 -.07  .19  .09 -.02
    192  .11  .18   .1 -.07  .21  .05 -.05
    193   .1  .19  .08 -.08  .18  .09 -.05
    194   .1  .17  .07 -.08   .2  .12 -.06
    195   .1  .16  .08 -.07  .21   .1 -.05
    196  .12  .15  .07 -.07  .27  .11 -.06
    197  .13  .14  .07 -.06  .31  .11 -.01
    198  .16   .2  .09 -.05  .34  .12 -.03
    199  .17  .24   .1 -.05  .33  .15 -.02
    200  .18  .27  .12 -.05  .34  .16 -.04
    201  .19  .24  .13 -.04  .37  .12 -.05
    202  .18  .21  .12 -.05  .37  .09 -.07
    203  .19   .2  .09    0  .37  .08 -.11
    204  .22  .17  .08  .07  .41  .06 -.14
    205  .23  .17  .09  .09  .42  .04 -.17
    206  .25  .19  .09   .1  .45    0 -.17
    207  .27  .16  .11  .13  .51 -.04 -.18
    208  .27  .15  .11  .14  .52 -.09 -.16
    209  .27  .11  .08  .16  .54 -.11 -.19
    210  .26  .09  .11  .15  .55 -.13  -.2
    211  .26   .1   .1  .14  .54 -.13 -.18
    212  .31  .15  .11  .15  .63 -.11 -.16
    213  .34  .17  .13  .16  .67 -.16 -.17
    214  .35  .21  .15  .17  .66 -.17 -.19
    215  .36  .26  .16  .17  .66 -.14  -.2
    216  .37  .29  .17  .16  .68 -.13 -.18
    217  .38  .33  .17  .17  .62 -.16 -.21
    218  .37  .29  .16  .18  .64 -.16 -.21
    219  .37  .27  .17  .17  .67 -.19 -.21
    end
    format %tq qdate
    Here is the code I currently have for 1 graph (there are 6 of them to be done in the data with the same formating):
    Code:
    * Create the scatter plot with custom labels and a 45-degree angle
    twoway (connect aaci_temp_low_au_avg qdate, msize(tiny)) ///
           (lfit aaci_temp_low_au_avg qdate, ///
           title("Low Temperature") ///
           xlabel(, format(%tq) angle(45) grid) /// Clean year labels, angled at 45 degrees
           ylabel(-0.2(0.1)0.3, grid) ///
           xtitle("") ///
           legend(off) ///
           lwidth(medium) lcolor(red) lpattern(solid)) ///
           , name(temp_low, replace)
    I would like to have a few things in this graph:
    1) On the x-axis, I would like to have the year only, every 5 years, with the 45 degree angle. I do not want to see the "q1" for quarterly date since the dataset is tsset qdate
    2) I would like to have the slope, intercept and R2 of the fitted red curve at the bottom of the graph, where the title of the x-axis usually goes, or somewhere easy to read. That can be presented as Y = a + b X and R2= for instance.
    3) I would like to combine the 6 subplots in one graph as 3 column and 2 rows. I would like to make sure we can still read the fitted curve estimates

    can someone help me with that? Thanks!


  • #2
    1) See https://journals.sagepub.com/doi/pdf...867X0800700410 for some relevant ideas.

    2) See aaplot from SSC for some ideas. If preferred, borrow or steal some of the code.

    3) graph combine, and good luck with that goal, which may be hard to achieve.

    Comment


    • #3
      I have looked at all these and I have tried to program it unsuccessfully. Would you be able to provide the code? Thank you in advance Nick.

      I have managed to combine them:
      Code:
      * Combine the individual graphs into a 3x2 layout
      graph combine temp_low rainfall sea_level cdd wind dry_days, col(3) row(2) ///
                    title("Trends in Extreme Weather Events Over Time") ///
                    ycommon xcommon

      Comment


      • #4
        Hi Nick Cox , I was wondering if you had a chance to review my code and help me on that. It would be great if you could provide me with the actual code, I have gone through several help files unsuccessfully. Thanks!

        Comment

        Working...
        X