Statalist The Stata Listserver

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

st: follow-up: trouble expanding a macros

From   Robert Kraut <>
Subject   st: follow-up: trouble expanding a macros
Date   Sun, 05 Mar 2006 13:57:52 -0500


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_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_freshmen\transition\
di  "`dir'""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'

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_freshmen\transition\"

. di "`dir'""withlag_2sls.dta"

. di "`dir'""withlag_2sls.dta"

. use "`dir'""withlag_2sls.dta", clear
invalid '"withlag_2sls.dta'

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

Robert Kraut


Date: Sat, 4 Mar 2006 17:07:28 -0500
From: "Austin Nichols" <>
Subject: Re: st: macro with a dot

  local  dir F:\\\0_freshmen\transition\
 di " `dir' "
 di  `dir'
to see where you have gone wrong.

On 3/4/06, Robert Kraut <> wrote:

I am trying to create a macro to refer to the directory where data and
files are stored, so I can move do files easily between computers. I
define the dir macro as:
   local  dir F:\\\0_freshmen\transition\
But when I try to refer to dir's values, I get an error, as if the dir
value is broken at the dot included in a directory names:

    dis `dir'
    data\0_freshmen\transition\ invalid name

*   For searches and help try:

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