0
votes

I am working in Stata with demand and supply for electricity. One of the tasks are to: "Create a new variable called heatd (heating days) which equals the number of degrees below 17C"

I have attempted this in Stata, googled and searched here, but I am not sure what is meant by this. Am I meant to make a dummy variable?

If anyone can help me with i.e. hints, state code for this I would be very grateful.

1
No explanation of data and no attempt at code. What are your variable names? Do you have daily data, or what? Over what time period is heating degree days to be calculated? Do you have data for one place or several? There is an easy answer, but you are, to be blunt, expected to work harder for it.Nick Cox
It is time series data, set daily, for a certain time (9-10 am). Mentionable variables are "date", "temp", "price", "production", "consumption".Christopher
Sorry, did not mean to press enter. Data is for one specific area. I have managed all other assignments without too much difficulty, but am kind of stuck here for some reason.Christopher
OK, but over what time period is heating degree days to be calculated?Nick Cox
There is no information on this as I see it, so I assume for the whole period, that is for all my data (?)Christopher

1 Answers

0
votes

Some will judge me tough on the questioner already, so here is a reproducible example. The idea is that we switch on heating when it drops below 17 deg C (hereafter 17C), so the temperature rise needed is (17 - temp)C in one day if the temperature is below 17C and 0C otherwise. It is common to sum that over months, seasons or years; the questioner doesn't know about that, so I point in the direction of egen's total() function as the best tool. Either for individual days or summed over longer periods the units of measurement are deg C days or degree days with a convention about which temperature scale is being used (Celsius or Fahrenheit, etc.). Some may want to think of this graphically as a an area on a temperature-time graph, or as an integral approximated discretely.

. clear 

. input temp date 

          temp       date
  1. 19     1
  2. 18     2
  3. 17     3    
  4. 16     4   
  5. 15     5
  6. end 

. gen heatday = max(0, 17 - temp) 

. list

     +-----------------------+
     | temp   date   heatday |
     |-----------------------|
  1. |   19      1         0 |
  2. |   18      2         0 |
  3. |   17      3         0 |
  4. |   16      4         1 |
  5. |   15      5         2 |
     +-----------------------+

The heart of the matter is thus max(0, 17 - temp). Another way to do it in Stata could be cond(temp < 17, 17 - temp, 0) which divides opinion according to whether it is too long (bad) or perhaps more explicit (good).