[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Wang,Le" <[email protected]> |

To |
<[email protected]> |

Subject |
st: Re: loop within loop |

Date |
Mon, 18 Oct 2004 02:47:15 -0500 |

Actually I also tried the following, forvalues i = 1988(1)2003 { forvalues j = 1(1)12 { matrix accum R`i'`j' = a b c d e if year == `i' & month == `j', nocons dev matrix R`i'`j' = corr(R`i'`j') replace corrab = R`i'`j'[1,1] if year == `i' & month == `j' & corrab == . } } Can anyone can tell me where i am wrong? Thanks. Best, Le ----- Original Message ----- From: "Wang,Le" <[email protected]> To: <[email protected]> Sent: Monday, October 18, 2004 2:40 AM Subject: st: loop within loop > Hi dear statalister, > > I have a question on loop within loop. I have the following data set > > year month date a b c > 88 1 1 .2 .5 .3 > . 1 2 .3 .6 .4 > . 1 3 .4 .7 .5 > . 2 1 .1 .2 .7 > . 2 2 .4 .5 .9 > . 2 3 .6 .7 1 > 89 1 1 .2 .5 .3 > . 1 2 .3 .6 .4 > . 1 3 .4 .7 .5 > . 2 1 .1 .2 .7 > . 2 2 .4 .5 .9 > . 2 3 .6 .7 1 > > I could program the correlation by year as follows, > > g corrab = . > > forvalues i = 1988(1)2003{ > matrix accum R`i' = a b c if year == `i', nocons dev > matrix R`i' = corr(R`i') > replace corrab = R`i'[2,1] if year == `i' & corrab == . > } > > However, now I want to calculate the correlation between a and b by year > and month. What should I do?? I tried the following, but it doesnot work. > > forvalues i = 1988(1)2003 { > local j = 1 > while `j' < 13{ > matrix accum R`i'`j' = a b c d e if year == `i' & month == `j', > nocons dev > matrix R`i'`j' = corr(R`i'`j') > replace corrab = R`i'`j'[1,1] if year == `i' & month == `j' & > corrab == . > local `j' = `j' + 1 > } > } > > Thanks a lot for your kind help. > > Best, > > Le > > * > * For searches and help try: > * http://www.stata.com/support/faqs/res/findit.html > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Using 2 vars to make 1 in presence of missing***From:*SamL <[email protected]>

**st: loop within loop***From:*"Wang,Le" <[email protected]>

- Prev by Date:
**st: loop within loop** - Next by Date:
**st: stata graphs (stata 8), y- or x-label as text over two lines** - Previous by thread:
**st: loop within loop** - Next by thread:
**st: RE: Using 2 vars to make 1 in presence of missing** - Index(es):

© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |