Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: follow-up: trouble expanding a macros


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   st: Re: follow-up: trouble expanding a macros
Date   Mon, 06 Mar 2006 07:26:39 -0500

You just have too many quotes. The -display- command can deal with multiple quote-delimited strings pushed up against each other, but the -use- command cannot. Try:

use `dir'withlag_2sls.dta, clear

or:

use " `dir'withlag_2sls.dta", clear

The latter syntax would allow you to have spaces in the file name. Another recommendation is that you use / instead of \ in file paths to avoid potential problems with macro expansion (if your file name were a local macro as well).

Michael Blasnik
[email protected]


----- Original Message ----- From: "Robert Kraut" <[email protected]>
To: <[email protected]>
Sent: Sunday, March 05, 2006 1:57 PM
Subject: st: follow-up: trouble expanding a macros



All,

I am still having trouble using a macro to refer to a windows directory:
Explicitly naming the directory & file in a use statement works works. E.g.,


use F:\0_stat.data\0_homenet.data\0_freshmen\transition\withlag_2sls.dta, clear
I can define the macro, and display seems to indicate that my definition
is correct:

local dir F:\0_stat.data\0_homenet.data\0_freshmen\transition\
di  "`dir'""withlag_2sls.dta"
F:\0_stat.data\0_homenet.data\0_freshmen\transition\withlag_2sls.dta
However, I still get an error when I add the file name, either
surrounding the filename in quotes or not:

use " `dir'""withlag_2sls.dta", clear
invalid '"withlag_2sls.dta'
r(198);

use " `dir'"withlag_2sls.dta, clear
invalid 'withlag_2sls.dta'
 > r(198);

Defining the macro using quotes around the directory names does not seem
to help. Again, the macro seems to expand correctly using the display
command, but not with the use command.

 > local dir "F:\0_stat.data\0_homenet.data\0_freshmen\transition\"

. di "`dir'""withlag_2sls.dta"
F:\0_stat.data\0_homenet.data\0_freshmen\transition\withlag_2sls.dta


. di "`dir'""withlag_2sls.dta"
F:\0_stat.data\0_homenet.data\0_freshmen\transition\withlag_2sls.dta

. use "`dir'""withlag_2sls.dta", clear
invalid '"withlag_2sls.dta'
r(198);

Any suggestions?  I must not be understanding something fundamental
about expanding macros.

Robert Kraut
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index