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: Overwritten?


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Overwritten?
Date   Sat, 4 Jan 2014 09:49:45 +0000

<>

For anyone lost but trying to follow, the problems here arise partly
because -sroot- (SJ) purports to support -if-, but does not. As an
Editor of the Stata Journal, I will write to the author myself and
request a bug fix, but private correspondence with the author will
necessarily remain private.

Otherwise this post is very puzzling. Steve Samuels took your problem
and, in essence,  solved it. You thanked him for his contribution. His
solution was in the same direction as my suggestion, but much better
in giving a code sketch and in showing that multiple -save-s are not
necessary.

His post

http://www.stata.com/statalist/archive/2013-12/msg00939.html

remains what you should be working with.

His approach can be extended to saving scalars from each regression as
you were also doing.

Putting together some of his code and some of yours

clear
save dhold, emptyok replace

forval i = 1/`limit' {

        display "Iteration of `i' of `limit"
        use yourdata if id ==`i', clear
        sroot fcf , residuals(res)
        gen which = "`: label (id) `i''"
        foreach v in Z14 Z24 Z34 Z4t Z3t Z2t Z1t {
                  gen `v' = r(`v')
        }
        append using dhold
        save dhold, replace
}

This remains a sketch. The combined dataset will repeat the -Z*-
scalars but that is soluble (e.g. with -collapse-).

Nick
[email protected]

On 4 January 2014 03:01, Francis, Richard N <[email protected]> wrote:
> Nick,
>
> I asked the author of the user-written program -sroot- to kindly make a revision to his program, but he declined.
>
> Previously, you suggested that I "would need to -save- the dataset you create each time and then -append- them all."
>
> I included your previous message in part below to help refresh your memory:
>
>> The nub of the matter I think is this. The program -srootfix-  by
>> Sergiy Radyakin  -preserve-s your original data, does some work and
>> when it's done -restore-s the original data. Thus it's futile adding
>> new variables to the dataset after -preserve-, as they will just
>> disappear at the -restore-. The -restore- is not explicit in the code,
>> but it's automatic given the -preserve-. The fact that -preserve-
>> requires a -restore- for the fix you originally asked for is explicit
>> in http://www.stata.com/statalist/archive/2013-11/msg00103.html
>>
>> Short of fixing a clone of -sroot- properly so that you don't need a work-around, or asking the original author to do that for you, it seems that you would need to -save- the dataset you create each time and then -append- them all.
>
> My question is this: within the loop below, how would I go about saving the datasets each time?
>
> forval i = 1/`limit' {
>          display "Iteration of `i' of `limit"
>          replace which = "`: label (id) `i''" in `i'
>          srootfix fcf if id == `i' , residuals(rez)
>          qui foreach v in Z14 Z24 Z34 Z4t Z3t Z2t Z1t {
>                 replace `v' = r(`v') in `i'
>          }
> }
>
> I think I can merge the resulting datasets, just no clue how to save them within a loop.
>
> Grateful for any direction you may suggest.
>
> Thank  you,
>
> Rick
>
> *
> *   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