Bookmark and Share

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: Files, Directories and Macros


From   Andrés Castañeda <[email protected]>
To   [email protected]
Subject   Re: st: Files, Directories and Macros
Date   Tue, 31 Jan 2012 15:26:43 -0500

Exactly, that is my point. Thanks.  It is working very well now.

Best,



On Tue, Jan 31, 2012 at 2:54 PM, Nick Cox <[email protected]> wrote:
> I now see the whole of what you are doing. My previous post was based on reading your previous.
>
> There is a small conflict here. First, the extended macro function does wrap each filename in " ". That's a good idea because many users, especially under MS Windows, put spaces in filenames, and Stata won't understand them otherwise.
>
> But you want to use " " around the whole of your string and that clashes with the " " already there. That's why you need to strip off the " ".
>
> But note that the -: dir- business will only work here if it finds precisely one file. If it finds none, -use- won't work. If it finds two or more, -use- won't work.
>
> Nick
> [email protected]
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Andrés Castañeda
> Sent: 31 January 2012 19:36
> To: [email protected]
> Subject: Re: st: Files, Directories and Macros
>
> Dear Nick,
>
> You are right, it worked. Thank you so much.
>
> The solution is therefore the line 3 of the following sequence:
>
> local dir "C:/Temp"
> local data: dir "`dir'" files "*.dta"
> local data `data'
> use "`dir'/`data'", clear
>
>
> Best,
>
> Andres
>
>
> On Tue, Jan 31, 2012 at 1:37 PM, Nick Cox <[email protected]> wrote:
>> I disagree. I expect those " " are there precisely because you put them there. If previously to this you had
>>
>> . local data `""example.dta""'
>>
>> then you are insisting that the " " are part of the macro, not delimiters. Re-define
>>
>> . local data example.dta
>>
>> and everything should work.
>>
>> Nick
>> [email protected]
>>
>> Andrés Castañeda
>>
>> I think there is something weird with the extended function of the macros:
>> If I type,
>>
>> macro dir
>> _data:          "example.dta"
>> _dir:           C:\Temp
>>
>> Notice that macroname data is enclosed in double quotes while the
>> macroname dir is not.
>>
>> how can i get with macros the following path: "C:/Temp/example.dta"
>> ???? I tried the forward slash instead of the backward slash and I
>> still got an error:
>>
>> use "`dir'/`data'", clear
>> invalid 'example.dta'
>>
>>
>> Thanks,
>>
>>
>> On Tue, Jan 31, 2012 at 10:16 AM, Maarten Buis <[email protected]> wrote:
>>> 2012/1/31 Andrés Castañeda :
>>>> I have a problem using macros to organize files. Let's say that in the
>>>> folder "C:\Temp" I have a UNIQUE dta file named "example.dta". I need
>>>> to call this file in Stata by using macros.
>>> <snip>
>>>>  use "$dir\"`data', clear
>>>> invalid '"example.dta'
>>>
>>> See: Nicholas J Cox (2008) Stata tip 65: Beware the backstabbing
>>> backslash. The Stata Journal, 8(3): 446-447.
>>> <http://www.stata-journal.com/article.html?article=pr0042>
>>>
>>> In short, the answer is:
>>> use "$dir/`data'", clear
>>>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/



-- 
___

Best,


Andrés Castañeda
World Bank, LAC-PREM
Research Associate
[email protected]
Tel 1(202) 677 - 8971
1850 I st, NW, Washington, DC.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index