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: -rolling, saving()- and -tempfile- error
From
Sergiy Radyakin <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: -rolling, saving()- and -tempfile- error
Date
Mon, 3 Feb 2014 23:12:08 -0500
Roberto, this happens because in the syntax of -rolling- we can see
(in *! version 1.3.0 12apr2013):
SAving(string asis) ///
and in the help for -syntax- we can read:
"asis specifies that the option's arguments be returned just as the user
typed them, with quotes (if specified)"
Here is an executable mini example:
do http://radyakin.org/statalist/2014/20140203_2252.do
So in THIS particular syntax the quotes matter.
Digging deeper, here is also something important: the parsing of the
saving() option is done in the _prefix_saving.ado, which is (seems to
me) buggy, since e.g. the following is a perfectly valid Stata dataset
name (as we can see):
. save "t:\test.dta.dta.1", emptyok
(note: dataset contains 0 observations)
file t:\test.dta.dta.1 saved
But the _prefix_saving.ado is handling it this way:
local ss : subinstr local fname ".dta" ""
confirm new file `"`ss'.dta"'
Which means:
local fname "test.dta.dta.1"
local ss : subinstr local fname ".dta" ""
display `"`ss'.dta"'
Results in: test.dta.1.dta
which is missing one .dta before .1.
Perhaps there are other mechanisms here, which do not allow such
filenames to reach this code. But a safer handling code is probably
feasible without much penalty.
Best, Sergiy
On Mon, Feb 3, 2014 at 9:32 PM, Roberto Ferrer <[email protected]> wrote:
> Running the following code does not work:
>
> *------------- begin code ----------------
>
> clear all
> set more off
>
> * Load data
> sysuse sp500
> tsset date
>
> tempfile aux results
>
> * Set fixed independent variable
> local var open
>
> foreach depvar of varlist high low close volume {
>
> rolling _b, window(30) saving("`aux'", replace): regress `depvar' `var'
> use "`aux'", clear
> rename (_b_`var' _b_cons) (b_`depvar'_`var' b_cons_`depvar'_`var')
>
> capture noisily merge 1:1 start end using "`results'"
> capture noisily drop _merge
> save "`results'", replace
>
> sysuse sp500, clear
> tsset date
> }
>
> * Check results
> use "`results'"
> browse
>
>
> *------------------ end code ----------------------
>
> The error is:
>
> file /tmp/St05392.000001" saved
> file /tmp/St05392.000001 not found
> r(601);
>
> When substituting this
>
> rolling _b, window(30) saving("`aux'", replace): regress `depvar' `var'
>
> for this
>
> rolling _b, window(30) saving(`aux', replace): regress `depvar' `var'
>
> it works fine. I thought the double quotes surrounding the -tempfile-
> -aux- were harmless. What's going on here? According to the error
> output, there's a " (double quote) getting saved in the file name.
> With the substitution this doesn't happen:
>
> file /tmp/St05392.000001 saved
>
> I'm using Stata 12.1 for Unix, Revision 09 Jul 2013.
> *
> * 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/