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]

From |
Steve Samuels <sjsamuels@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Overwritten? |

Date |
Tue, 31 Dec 2013 12:00:08 -0500 |

Your problem is easy to diagnose, I think: -sroot.ado contains a -predict residuals, res- command. This is equivalent to generating a new variable. At the second iteration, -predict- should fail because the data set already contains a variable named "res". If I am correct, the problem has nothing to do with the -if- error that Sergiy's -srootfix- is designed to work around. In such situations, I use a -keep if-, -append-, and -save, replace- approach. Below is the outline of a do file for you to fill in. You should be able to call -sroot- directly, as -srootfix- is no longer needed. **********CODE BEGINS**************** /* Create a data set to hold results */ clear save dhold, emptyok replace forval i = 1/`limit' { use yourdata, clear keep if id ==`i' /* Do something that generates variables */ append using dhold save dhold, replace } **************CODE ENDS************** Steve Steven J Samuels sjsamuels@gmail.com 18 Cantine's Island Saugerties NY 12477 USA tel: 845-246-0774 On Dec 30, 2013, at 9:28 PM, Francis, Richard N wrote: Nick, Thank you for your advice. In your experience, is there a reasonable expectation that the original author will alter the program? Rick -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox Sent: Monday, December 30, 2013 7:06 PM To: statalist@hsphsun2.harvard.edu Subject: Re: st: Overwritten? <> Side details first: A convention suggested for Statalist is to use notation such as -foo- to flag names of commands, variables, etc. as used in Stata. That way, for example, the word replace is to be understood as just ordinary English but the word -replace- is easy to spot as something that could be typed in Stata. A convention is just that, but I like the Statalist convention, and have often commended it. The different convention you're introducing here of using -FOO instead does not strike me as a good one, if only for the reason that upper case is usually not idiomatic Stata, but that's a personal view. For the record, -sroot- here is from Stata Journal 9(3) 2009. 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. Fixing this properly is the better solution, as then your overall problem should yield to -statsby-. Nick njcoxstata@gmail.com On 30 December 2013 21:59, Francis, Richard N <rnfrancis@utep.edu> wrote: > Have an option within a called program -SROOTFIX which generates residuals for a regression command. > > However, the variable containing the residuals -RES is absent. > > The called program -SROOTFIX actually calls another program -SROOT. > > Separate execution of -SROOT retains the residuals variable -RES, which suggests that something within the -SROOTFIX pgm overwrites the residuals variable -RES. > > The master program is as follows: > > forval i = 1/`limit' { > display "Iteration of `i' of `limit" > replace which = "`: label (id) `i''" in `i' > srootfix fcf if id == `i' , residuals(res) > qui foreach v in Z14 Z24 Z34 Z4t Z3t Z2t Z1t { > replace `v' = r(`v') in `i' > } > } > > I have executed the program with the -replace command. > > However, the residuals variable -RES continues to be absent. > > The contents of -SROOTFIX are as follows: > > *! By Sergiy Radyakin, 2013 > *! Fixes problem of -if- modifier [suspected] not working in public (SJ) version of -sroot-. > ** See http://www.stata.com/statalist/archive/2013-11/msg00366.html > > program define srootfix > version 9.2 > syntax varname(ts) [if] [in] ,[*] > preserve > marksample touse > keep if `touse' > sroot `varlist' , `options' > end > > ** end of file ** > > Any ideas for the absence of the residuals variable -RES are greatly appreciated. > * * 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/

**Follow-Ups**:**RE: st: Overwritten?***From:*"Francis, Richard N" <rnfrancis@utep.edu>

**References**:**st: Overwritten?***From:*"Francis, Richard N" <rnfrancis@utep.edu>

**Re: st: Overwritten?***From:*Nick Cox <njcoxstata@gmail.com>

**RE: st: Overwritten?***From:*"Francis, Richard N" <rnfrancis@utep.edu>

- Prev by Date:
**st: New version of -bspline- on SSC** - Next by Date:
**st: New package -polyspline- on SSC** - Previous by thread:
**RE: st: Overwritten?** - Next by thread:
**RE: st: Overwritten?** - Index(es):