Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

RE: st: FORVAL loop incomplete


From   "Francis, Richard N" <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: FORVAL loop incomplete
Date   Sat, 9 Nov 2013 16:21:55 +0000

Again I'm sorry for the shortcomings.

The program is not complete, but ...

The ULTIMATE goal is to construct a three-observation, eight-variable dataset (the seven vars you see in the loop plus one ID variable), which can be extended to additional observations.

I'm sorry for the burden guys, I don't speak Stata, only trying to survive.

Thank you!


Rick Francis
Associate Professor
Department of Accounting
College of Business Administration
University of Texas at El Paso
500 W. University Avenue
El Paso, TX  79968
Office: 915-747-7953
FAX: 915-747-8618
Email:  [email protected]


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of William Buchanan
Sent: Saturday, November 09, 2013 9:13 AM
To: [email protected]
Subject: Re: st: FORVAL loop incomplete

1.) You need to tell us how you are defining 'r(max)'.  If you are using this to loop over observations you could use _N.
2.) You don't need to print the results to the screen during each pass and can just reference the returned values on their own
3.) you are appending something to your dataset only to undo that work when you restore the original dataset from memory
4.) if your goal is to replace values for variables you could use the _if_ condition to reference the single ID of interest and replace the values for the same observation.  

It would probably help if you explained what it is you are trying to accomplish here since it isn't completely clear and there are several different syntax issues at work simultaneously.

Sent from my iPhone

> On Nov 9, 2013, at 9:53, "Francis, Richard N" <[email protected]> wrote:
> 
> Hello Statalist,
> 
> Have a simple FORVAL loop which should result in multiple cycles.
> 
> However, she only cycles once. I'm sure the answer is obvious to experienced Stata users (which I am not).
> 
> The loop is as follows:
> 
> 
> forval i = 1/`r(max)' {
>    preserve
>    keep if id == `i'
>    sroot fcf 
>               return list
>               ereturn list          
>               replace Z14 = r(Z14) in `i'
>               replace Z24 = r(Z24) in `i'
>               replace Z34 = r(Z34) in `i'
>               replace Z4t = r(Z4t) in `i'
>               replace Z3t = r(Z3t) in `i'
>               replace Z2t = r(Z2t) in `i'
>               replace Z1t = r(Z1t) in `i'
>               append using new
>    restore                            
> }
> 
> I am grateful for any thoughts anyone may have.
> 
> Thank you!!
> 
> Rick Francis
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/

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

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


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index