Announcement

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

  • Rainfall Data

    Originally posted by Andrew Musau View Post

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(reg year month rain precipitation)
    1 2004 1 16.82793 15.3875
    1 2004 2 9.908793 5.84
    1 2004 3 7.752069 7.2333
    1 2004 4 11.648196 15.12
    1 2004 5 25.20661 32.007
    1 2004 6 31.033167 26.2933
    1 2004 7 26.338245 28.8567
    1 2004 8 21.875484 21.63
    1 2004 9 16.780794 13.1267
    1 2004 10 18.437414 19.59
    1 2004 11 20.098333 19.315
    1 2004 12 26.05887 22.55
    1 2005 1 16.82793 39.05
    end
    
    gen yearmonth= ym(year, month)
    format yearmonth %tm
    rangestat (mean) rain, interval(yearmonth -8 0) by(reg)
    Now, your sample starts in Jan. 2004, so we cannot calculate a 9 month historical average for this month due to lack of data. The command above will give you the 1 month average which is that month's average rainfall. For Feb. 2004, you will get a 2 month average (Jan and Feb, 2004). Only in Sep. 2004 and beyond will you get a true 9 month average. If you want to blank out averages less than 9 months due to no data, you can subsequently

    Code:
    bys reg (yearmonth): replace rain_mean=. if _n<9


    This is not clear. How long is long-run?
    Dear Statalist,

    I would like to use rangestat to calculate the rainfall in the 12 months after the birth. I was wondering if the code below is relevant:
    rangestat (mean) rain, interval(yearmonth 11 0) by (reg)
    Thanks for your reply.

    Regards!

  • #2
    I would like to use rangestat to calculate the rainfall in the 12 months after the birth. I was wondering if the code below is relevant:
    rangestat (mean) rain, interval(yearmonth 11 0) by (reg)
    From rangestat's (SSC) documentation, the following is relevant:

    By specifying interval(year -4 0), the interval for an observation in 1950 for example will amount to [1950-4, 1950] and evaluate to
    [1946, 1950].
    Therefore in your case, the interval [yearmonth 11 0] evaluates to [1+11, 1] = [12, 1] for yearmonth=1. This is inconsistent as the lower limit exceeds the upper limit. Instead, you want

    Code:
    rangestat (mean) rain, interval(yearmonth 1 12) by(reg)
    Last edited by Andrew Musau; 24 May 2020, 14:22.

    Comment

    Working...
    X