Announcement

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

  • Sum loops to transform daily variables into monthly variables

    Hello to all,

    I am processing weather data and I need to sum daily variables into monthly variables. Small problem: I have to do this for 524 individuals from 1981 to 2009 for which I have as many variables of as days. So I have to go through forvalues loops to avoid spending 2 months on it.

    By chance, all the variables have the same construction in terms of name, they are all of type: P`year'`month'`day'.

    To make these sums I had the idea to use this code :

    forvalue m=1981/2009 {
    forvalue g=1/9 {
    egen P`m'`g'=sum(P`m'0`g'*), by(idmc)
    }
    }
    forvalue m=1981/2009 {
    forvalue g=10/12 {
    egen P`m'`g'=sum(P`m'`g'*), by(idmc)
    }
    }

    the red asterix is not in the code, this is the reason of my post. As the number of days is not equal across months I can't use a loop like for years or months, otherwise stata will return me an error message. So I'm looking for something I should put in place of the red asterix to make stata understand that I want it to take all the possible values for the part concerning the days.

    (the fact that there are two loops, one for the first 9 months and another one for the last 3 months highlights another problem I had, which is that I can't make a loop with 01/12, it will be counted as 1/12 or the name of my variables is 01, 02, 03 for the first months and not 1, 2 3)

    if something is not clear don't hesitate to ask me questions, I can for example show an extract of the data !

    Thanks in advance !

  • #2
    Sorry it's the wrong forum, I've reposted it in general but I don"t konw how to erase it from here

    Comment

    Working...
    X