Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Rolling window correlations for all possible pairs of variables


From   <A.C.Tuncer@lse.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Rolling window correlations for all possible pairs of variables
Date   Mon, 13 Aug 2012 13:21:22 +0100

Dear Maarten
This works like a charm.
Many thanks!
Regards,
Coskun

 
________________________________

From: owner-statalist@hsphsun2.harvard.edu on behalf of Maarten Buis
Sent: Mon 13/08/2012 12:40
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Rolling window correlations for all possible pairs of variables



On Mon, Aug 13, 2012 at 1:30 PM,  <A.C.Tuncer@lse.ac.uk> wrote:
> This is very helpful and works well, however I receive an error message when a pair of variables do not have any overlapping observations. Say var1 has observations in period 1900-1960, whereas var2 has observations in 1970-2000. Thus as it is not possible to calculate the corr, the calculations simply stop. Is there any way to force the do-file keep calculating?

replace the block:

else {
    use `orig', clear
    rolling r(rho), window(10) saving(`temp', replace) : ///
        cor ``i'' ``j''
    use `temp', clear
    rename _stat_1 r_``i''_``j''
    merge 1:1 start using `tofill'
    assert _merge == 3
    drop _merge
    save `tofill', replace
}

with:

else {
    use `orig', clear
    capture rolling r(rho), window(10) saving(`temp', replace) : ///
        cor ``i'' ``j''
    if !_rc {
        use `temp', clear
        rename _stat_1 r_``i''_``j''
        merge 1:1 start using `tofill'
        assert _merge == 3
        drop _merge
        save `tofill', replace
    }
}

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl <http://www.maartenbuis.nl/> 
---------------------------------

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



Please access the attached hyperlink for an important electronic communications disclaimer: http://lse.ac.uk/emailDisclaimer

<<winmail.dat>>



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index