Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: Programming, rollreg, gaps, and memory


From   Cameron Hooper <[email protected]>
To   [email protected]
Subject   Re: st: Re: Programming, rollreg, gaps, and memory
Date   Mon, 18 Apr 2005 16:48:56 -0400

Michael Blasnik wrote:
> I think you may need to add:
>
> drop `res'
>
> at the end of your loop.

Hi Michael

Thanks for your suggestion. I did not realize -tempvar- operated in this fashion. Added the -drop- command fixed that particular problem. (Others have since arisen!) Just to convince myself I wrote the following test program to explore the behaviour of -tempvar-. Other complete newbies might also find it interesting:

. clear
. set obs 5
obs was 0, now 5

. gen x = _n * uniform()

. capture drop nv
. capture program drop tmpv

. program tmpv
1. qui {
2. gen nv = .
3. forvalues i = 1/5 {
4. tempvar t
5. gen `t' = x[_n]
6. describe
7. replace nv = r(k) in `i'
8. }
9. }
10. end
.
. tmpv
. list

+---------------+
| x nv |
|---------------|
1. | .5415702 3 |
2. | .0175157 4 |
3. | .921708 5 |
4. | 1.988945 6 |
5. | 4.485629 7 |
+---------------+

Yep. Each each iteration of the -forvalues- loop generates a new variable.

Thanks,

Cameron
*
* 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/




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