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   Sergiy Radyakin <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: FORVAL loop incomplete
Date   Sat, 9 Nov 2013 08:27:30 -0800

Rick,
1) N may be 180, but what is r(max)? In Stata r(max) is the result of
the previous command [of r-class]. You don't show us this command.
Please do.
2) The combination of "append using new" and "restore" does not make
sense, Whatever you append you immediately lose.
3) If append is meant to add one observation where you are saving the
results (dataset new is a blank one observation of the same layout as
the current dataset), consider using: expand in _N
4) If you want to accumulate the results of your tests, consider using
a matrix to hold the results, and avoid modifying the data.
Best, Sergiy

On Sat, Nov 9, 2013 at 8:14 AM, Francis, Richard N <[email protected]> wrote:
> I'm sorry, N = 180 obs, currently cycles through the first 60 (3 groups of 60 =180 total obs).
>
> Thank you!!
>
> Rick Francis
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
> Sent: Saturday, November 09, 2013 9:08 AM
> To: [email protected]
> Subject: Re: st: FORVAL loop incomplete
>
> Tell us what r(max) is.
> Nick
> [email protected]
>
>
> On 9 November 2013 15: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/
*
*   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