Announcement

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

  • #16
    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(ZS20003 ZS20004 ZS20005 ZS20006 ZS20007 ZS20008 ZS20009 ZS200010 ZS200011 ZS200012 ZS20011 ZS20012 ZS20013 ZS20014 ZS20015)
     .2480315 .53149605 .47244096 .37007874 .68503934 .62598425 .38188976 .38188976 .23622048 .35826772 .25590551 .25984251 .27952754  .2992126 .53543305
     .2519685 .42519686 .31102362 .35039371 .46850392 .53543305 .30314961 .24409449 .16535433 .32283464 .27559054 .23622048 .22834645 .19685039 .31889763
     .2480315 .53149605 .47244096 .37007874 .68503934 .62598425 .38188976 .38188976 .23622048 .35826772 .25590551 .25984251 .27952754  .2992126 .53543305
     .2480315 .53149605 .74409449 .64960629 .62204725 .68503934 .32677165 .35039371 .22834645 .33464566 .35039371 .30314961 .26377952 .33858266 .42519686
    .22834645 .55118108 .81889766 .61417323 .64566928 .66929132 .36614174 .33858266 .22440945 .31889763 .35039371 .31889763  .2519685 .35039371 .43307087
    end
    ------------------ copy up to and including the previous line ------------------

    Comment


    • #17
      I have monthly data from 2000 March to 2007 December.

      Comment


      • #18
        So, you no longer need the loop that appends the various monthly data sets. Instead you need to reshape the data to long layout and then create a monthly date variable. I notice that the variable names are different from before, so the new variable names need to be substituted into the code. All in all, the end result looks like this:

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input ClusterPoints double(ZS20003 ZS20004 ZS20005 ZS20006 ZS20007 ZS20008 ZS20009 ZS200010 ZS200011 ZS200012 ZS20011 ZS20012 ZS20013 ZS20014 ZS20015)
        1  .2480315 .53149605 .47244096 .37007874 .68503934 .62598425 .38188976 .38188976 .23622048 .35826772 .25590551 .25984251 .27952754  .2992126 .53543305
        2 .2519685 .42519686 .31102362 .35039371 .46850392 .53543305 .30314961 .24409449 .16535433 .32283464 .27559054 .23622048 .22834645 .19685039 .31889763
        3 .2480315 .53149605 .47244096 .37007874 .68503934 .62598425 .38188976 .38188976 .23622048 .35826772 .25590551 .25984251 .27952754  .2992126 .53543305
        4 .2480315 .53149605 .74409449 .64960629 .62204725 .68503934 .32677165 .35039371 .22834645 .33464566 .35039371 .30314961 .26377952 .33858266 .42519686
        5 .22834645 .55118108 .81889766 .61417323 .64566928 .66929132 .36614174 .33858266 .22440945 .31889763 .35039371 .31889763  .2519685 .35039371 .43307087
        end
        
        reshape long ZS, i(ClusterPoints) j(year_month) string
        gen year = real(substr(year_month, 1, 4))
        gen month = real(substr(year_month, 5, .))
        gen mdate = ym(year, month)
        format mdate %tm
        
        local first_month = tm(2003m3)
        local last_month = tm(2018m7)
        
        // CALCULATE THREE AND NINE MONTH LAGGING AVERAGES
        rangestat (mean) lag3_Zonal = ZS, by(ClusterPoints) interval(mdate -3 -1)
        rangestat (mean) lag9_Zonal = ZS, by(ClusterPoints) interval(mdate -9 -1)
        isid ClusterPoints mdate, sort
        Note: In the example data in #16, you did not provide the variable ClusterPoints. I just edited that in to the -dataex-, since that cluster identifying variable is essential. If it doesn't exist in your real data set, you need to create it.

        Comment

        Working...
        X