Dear Nick,
I have just tried your suggestion, `= `i' + 1' , and it works sucsessfully, no more error appears. Thank you very much for your help.
Best Regards
Hua
-------- Original-Nachricht --------
> Datum: Sun, 22 Mar 2009 17:16:28 -0000
> Von: "Nick Cox" <[email protected]>
> An: [email protected]
> Betreff: RE: st: RE: Group building according to given report dates and company
> This has already been addressed by Kit with a different approach that Hua
> declared successful.
>
> I just wanted to focus on the detail below.
>
> Within a structure like
>
> forval i = 1/11 {
>
> }
>
> any reference to `++i' increments the local macro i each time it is used.
>
> Note the sting: each time it is used.
>
> Next time round the loop the macro is reset to whatever -forval-
> determines.
>
> Thus suppose i = 1. Then the code
>
> replace period = `i' if date >= rep`i'+2 & date < rep`++i' & rep`++i'
> <rep`i'+120
>
> becomes
>
> replace period = 1 if date >= rep1 + 2 & date < rep2 & rep3 < rep2 + 120
>
> I don't know if that is what Hua intended, but I doubt it.
>
> Note that
>
> `= `i' + 1'
>
> is a good way to get one more than the value of macro i, without affecting
> the value of macro i.
>
> Nick
> [email protected]
>
> Hua Pan
>
> 2)When I use this loop:
> forvalues i = 1/11 {
> replace period = `i' if date >= rep`i'+2 & date < rep`++i'
> }
> I can calculate the cumulative return before the next report date. But
> there are two problems, an error appears because of `++i’: i=12 can’t be
> found. And it works only when there are complete 11 periods without missing
> value. When there missing values, periode 3 would be calculated from
> 16oct04 to 13apr05 (about 6 months), period 7 from 11feb06 to 30dec06
>
> I tried something like:
> forvalues i = 1/11 {
> replace period = `i' if date >= rep`i'+2 & date < rep`++i' & rep`++i'
> <rep`i'+120
> }
>
> I set 120, because I just want to sure that time space is about 3 months
> (90 days), not 6 months (180 days)or more. But it failed to work. The
> 3.Period is still calculated from 18oct2004 to 13apr2005, almost 6 months. I have
> really no idea why it happend. Do you have a better idea, so that error
> wouldn’t appear and it works well even when there are missing data? Any
> suggestion would be great appreciated. Thank you again, Michael.
>
>
> *
> * 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/
--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01
*
* 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/