Announcement

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

  • Generate variables to capture heat stress

    Dear all
    I have daily minimum and maximum temperature data from 697 weather stations across 311 districts.
    For each district i in month m of year t, I need to aggregate the daily temperature data into two threshold-based heat stress variables which are (1) growing degree-days GDD and (2) stress degree-days or SDD.

    The GDD and SDD variables are defined as follows
    Click image for larger version

Name:	Untitled.png
Views:	1
Size:	7.7 KB
ID:	1530928

    Where Tlow and Thigh are the maximum and minimum temperature in oC for district i on day d of month m and year t.
    Tlow is the lower threshold and takes the value of 10, Thigh is upper threshold and takes the value 30 and Tk takes the value 35

    GDDimt is heat accumulated within temperatures Tlow and Thigh and SDDimt is heat accumulated above Tk.

    Any suggestions how to implement these specifications?
    Last edited by Shailaja Tiwari; 06 Jan 2020, 07:12.

  • #2
    Detailed advice is not possible without seeing an excerpt of your data using -dataex-, as described in the FAQ. Having formulae and your description of their meaning is helpful, and you've done that *much* better than most postershere, but having a -dataex- excerpt would nevertheless be essential to getting detailed advice.

    So, without those, my suggestion is that you look at the min() and max() function described in -help egen-, and the use of "by varlist" with this command. The documentation is not entirely easy, but that's where you need to start. I presume your data is stored in the long format, with each each observation representing a particular station for a particular day/month/year. If not, you'll need to create that.

    I'd start here by computing the various max and min values using -egen- and then eyeballing them to see if they make sense. Then, I'd look at using the -total- function in -egen-, with a "by list," to add up these values.

    Also, another thing I find unclear is what you want for a final data file to analyze. It seems like you might want a data set in which each observation is a district for a particular year/month. It's possible in that case that you might be able to do with -collapse- what I describe doing with -egen-. It would be helpful if you said something like "In the end, I want a data set in which each observation is ...., containing variables that describe .... The ultimate purpose is to examine .... with ..... as the unit of analysis."

    Comment


    • #3


      Dear Mike thank you for your answer. Very remiss of me, here is an excerpt of my data. I have the mean, minimum and maximum temperature (in degree Celsius) defined for day, month and year for different weather stations. You are correct my data is in the long format.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(DATE MONTH YEAR) double(LAT LON) float(MEANT MINT MAXT id)
      1 1 1969 7.5 94.5  25.2 20.32 30.08   1
      1 1 1970 7.5 94.5  27.7 25.42 29.97   2
      1 1 1971 7.5 94.5 26.72 24.26 29.18   3
      1 1 1972 7.5 94.5 25.39 21.73 29.05   4
      1 1 1973 7.5 94.5 27.63 24.88 30.38   5
      1 1 1974 7.5 94.5 26.39 24.41 28.38   6
      1 1 1975 7.5 94.5 26.74 23.62 29.86   7
      1 1 1978 7.5 94.5 27.17 23.86 30.48   8
      1 1 1980 7.5 94.5 26.98 23.75  30.2   9
      1 1 1981 7.5 94.5  26.1 22.04 30.15  10
      1 1 1982 7.5 94.5 26.98 24.41 29.55  11
      1 1 1983 7.5 94.5 25.73 21.64 29.81  12
      1 1 1988 7.5 94.5 25.88 22.01 29.76  13
      1 1 1989 7.5 94.5 27.24 23.92 30.55  14
      1 2 1969 7.5 94.5 25.27 20.83 29.71  15
      1 2 1970 7.5 94.5 27.71 25.08 30.35  16
      1 2 1971 7.5 94.5 26.45 23.21 29.68  17
      1 2 1972 7.5 94.5 27.03 23.47 30.59  18
      1 2 1973 7.5 94.5 27.99 24.42 31.57  19
      1 2 1974 7.5 94.5 27.09  24.8 29.39  20
      1 2 1975 7.5 94.5 26.82 23.28 30.36  21
      1 2 1978 7.5 94.5 27.59 24.79 30.38  22
      1 2 1981 7.5 94.5 27.81 24.44 31.17  23
      1 2 1983 7.5 94.5 24.82 20.63    29  24
      1 2 1988 7.5 94.5 26.59 21.78 31.39  25
      1 2 1989 7.5 94.5 26.85 22.54 31.15  26
      1 3 1969 7.5 94.5  26.8 22.44 31.17  27
      1 3 1970 7.5 94.5 26.33 21.67 30.98  28
      1 3 1971 7.5 94.5 25.58 22.51 28.65  29
      1 3 1972 7.5 94.5 24.35 18.69    30  30
      1 3 1973 7.5 94.5 28.19 24.51 31.86  31
      1 3 1974 7.5 94.5 26.94 24.24 29.64  32
      1 3 1975 7.5 94.5 27.57 24.92 30.22  33
      1 3 1977 7.5 94.5 26.89  23.4 30.37  34
      1 3 1978 7.5 94.5 28.09 24.97 31.22  35
      1 3 1980 7.5 94.5 25.85 20.79 30.92  36
      1 3 1981 7.5 94.5 26.94 22.66 31.23  37
      1 3 1982 7.5 94.5 27.32 23.39 31.25  38
      1 3 1983 7.5 94.5 27.43 23.34 31.53  39
      1 3 1989 7.5 94.5 27.54 23.88  31.2  40
      1 4 1969 7.5 94.5 27.52 23.36 31.68  41
      1 4 1970 7.5 94.5 27.12 22.96 31.27  42
      1 4 1971 7.5 94.5 27.65 24.48 30.81  43
      1 4 1972 7.5 94.5 27.06 22.27 31.84  44
      1 4 1973 7.5 94.5 27.42 24.01 30.84  45
      1 4 1974 7.5 94.5 27.93 24.71 31.15  46
      1 4 1975 7.5 94.5 27.54 23.48 31.61  47
      1 4 1977 7.5 94.5 28.46 25.27 31.66  48
      1 4 1978 7.5 94.5 27.48 23.04 31.92  49
      1 4 1980 7.5 94.5 27.37 22.24  32.5  50
      1 4 1981 7.5 94.5 27.99 23.42 32.55  51
      1 4 1982 7.5 94.5 26.87 21.08 32.67  52
      1 4 1983 7.5 94.5 27.57 22.87 32.28  53
      1 4 1988 7.5 94.5 26.82 21.91 31.72  54
      1 4 1989 7.5 94.5 28.52 24.38 32.66  55
      1 5 1969 7.5 94.5 28.94 24.53 33.35  56
      1 5 1970 7.5 94.5 27.13 23.75  30.5  57
      1 5 1971 7.5 94.5 26.81 23.57 30.05  58
      1 5 1972 7.5 94.5 27.72 23.82 31.61  59
      1 5 1973 7.5 94.5 28.35 25.11 31.59  60
      1 5 1974 7.5 94.5 27.29 25.12 29.46  61
      1 5 1975 7.5 94.5 27.35 23.19 31.51  62
      1 5 1977 7.5 94.5 28.82 24.66 32.97  63
      1 5 1978 7.5 94.5 27.85 23.84 31.85  64
      1 5 1981 7.5 94.5 28.36 24.54 32.18  65
      1 5 1982 7.5 94.5 28.54 24.14 32.93  66
      1 5 1988 7.5 94.5 28.21 24.99 31.44  67
      1 5 1989 7.5 94.5 28.38  24.9 31.86  68
      1 6 1969 7.5 94.5 27.39 25.02 29.76  69
      1 6 1970 7.5 94.5 27.04 23.83 30.24  70
      1 6 1971 7.5 94.5 27.22 24.46 29.98  71
      1 6 1972 7.5 94.5 27.93 24.77  31.1  72
      1 6 1973 7.5 94.5  26.9 24.38 29.43  73
      1 6 1974 7.5 94.5 28.36 25.88 30.84  74
      1 6 1975 7.5 94.5  26.8 23.25 30.36  75
      1 6 1977 7.5 94.5 28.64 25.72 31.55  76
      1 6 1978 7.5 94.5  27.8 24.89 30.71  77
      1 6 1980 7.5 94.5 28.34 24.45 32.22  78
      1 6 1981 7.5 94.5 27.62 24.05 31.19  79
      1 6 1982 7.5 94.5 26.48 23.02 29.93  80
      1 6 1983 7.5 94.5 27.47  23.8 31.15  81
      1 6 1988 7.5 94.5 29.14 27.06 31.22  82
      1 6 1989 7.5 94.5 26.41 22.69 30.13  83
      1 7 1969 7.5 94.5 26.05 23.46 28.65  84
      1 7 1970 7.5 94.5  26.8 23.64 29.97  85
      1 7 1971 7.5 94.5 25.89 23.35 28.43  86
      1 7 1972 7.5 94.5 25.67 22.83 28.51  87
      1 7 1973 7.5 94.5 25.94 23.55 28.33  88
      1 7 1974 7.5 94.5 27.54 24.54 30.54  89
      1 7 1975 7.5 94.5 25.97 23.29 28.65  90
      1 7 1977 7.5 94.5 28.61  26.3 30.92  91
      1 7 1978 7.5 94.5 25.86 22.81 28.91  92
      1 7 1980 7.5 94.5 26.71 23.31  30.1  93
      1 7 1981 7.5 94.5 25.72 21.79 29.65  94
      1 7 1982 7.5 94.5 27.83 24.36  31.3  95
      1 7 1983 7.5 94.5 27.54 23.81 31.27  96
      1 7 1988 7.5 94.5 27.05 23.37 30.73  97
      1 7 1989 7.5 94.5 28.36 25.37 31.35  98
      1 8 1969 7.5 94.5 28.39 26.18 30.61  99
      1 8 1970 7.5 94.5 26.08 23.21 28.96 100
      end
      My purpose to see the impact of the GDD and SDD variables on yield. I have the yield data for 311 districts (my panel variable) from 1970 to 2018 in a separate file.
      However, I need to calculate the GDD and SDD variables using the formula above and the data in the excerpt.
      This is where I am getting stuck. I am not sure how to code the above formula.
      Also I assume that I will have to implement the formula above and calculate the GDD and SDD variables and then use the collapse option??

      Comment


      • #4
        Shailaja Tiwari Hi! I was wondering if you managed to find a way to code the GDD and SDD formulae? I am stuck in a similar situation.

        Comment

        Working...
        X