Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: Overwritten? |
Date | Tue, 31 Dec 2013 02:05:53 +0000 |
<> 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/