Statalist


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

RE: st: RE: Group building according to given report dates and company


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: Group building according to given report dates and company
Date   Sun, 22 Mar 2009 17:16:28 -0000

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/



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