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: multiple merging


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: multiple merging
Date   Tue, 3 Apr 2012 11:51:32 +0100

The side-effects of =subinstr() were discussed in a recent thread.
Don't use it here. Use -: subinstr -.

Contrary to your earlier report, -nmerge- is not on SSC. It is from

http://www.ats.ucla.edu/stat/stata/ado/analysis

If you look at the code you will see that the program (not do-file)
doesn't have a  *! line. That's not illegal.

I have never used -nmerge- but I think your `" "' are not helping at
all. You probably need something more like

local files4 : subinstr local files ".dta" "", all
nmerge date using `files4'

On Tue, Apr 3, 2012 at 11:26 AM, Abhimanyu Arora
<[email protected]> wrote:
> Hi Nick
> Thanks very much indeed. Helps clear my understanding both of
> -gettoken- and the use of compound double quotes.
> Even as I await Ryan Knight's reply with regard to SSC's -mergeall-, I
> was trying using Mike M Mitchell's -nmerge- (the -which- command
> doesn't seem to display the version of the do file).
>
> The use of nmerge requires the file names in its syntax (simply
> separated by spaces, hence the reason for using the extended macro fcn
> clean—but error both with and without this)
>
> After the use of gettoken I get the file names but each in double
> quotes. Say the macro files contains the strings "file1.dta"
> "file2.dta" ...
>
> Assume we start with file0 (the one to which others will merge)
>
> Complementing with
> local files4=subinstr(`"`files'"',".dta","",.)
>
> I get
>
> . nmerge date using `"`files4'"'
> One or more filenames after 'using' required
> (no error though)
>
> di `"`files4'"'
>
> "file1" "file2"....and so on
>
> OR
>
> local files2 : list clean files
> local files3=subinstr(`"`files2'"',".dta","",.)
>
> I get
> . nmerge date using `"`files3'"'
> 'file2' found where nothing expected
>
> di `"`files3'"'
>
> file1 file2... and so on
>
> Not able to understand why this error. I thought the second option
> should work out but don't know what's blocking.
>
> Abhimanyu
>
> On Tue, Apr 3, 2012 at 9:48 AM, Nick Cox <[email protected]> wrote:
>> Your use of -gettoken- is quite illegal. -gettoken- is perhaps most
>> often used in this form
>>
>>  gettoken emname1 emname2 : emname3
>>
>> in which the -emname*- are extended macronames. Focus on the "names":
>> you are feeding -gettoken- with macro contents as the macro
>> _reference_ `r(files)' will get expanded by Stata before -gettoken-
>> sees it.
>>
>> Nor will r(files) be acceptable to -gettoken-.
>>
>> This is an example of will work:
>>
>> fs <whatever>
>> local files `" `r(files)' "'
>> gettoken first files : files
>>
>> In your case the -local- command may be enough. There is no need to
>> clean up the " " as they are there for a purpose, to bind names with
>> spaces.
>>
>> -fs- is from SSC.
>>
>> Nick
>>
>> On Mon, Apr 2, 2012 at 11:22 PM, Abhimanyu Arora
>> <[email protected]> wrote:
>>
>>> I have datasets which I need to merge into a single file. All files
>>> have a (string) variable that uniquely identifies observations in the
>>> files.
>>> There are two user-written commands I found in the SSC—mergeall (Ryan
>>> Knight) and nmerge(Michael N. Mitchell).
>>> I am facing problems with both.
>>>
>>> In the first case I get a type mismatch error even though I specify
>>> the string option with force
>>>
>>> In the second case I am unable to get my file names (except the first
>>> file) in a macro.  I used fs(Nick Cox) get the file names in r(files).
>>> Next I type in  gettoken first `r(files)' : `r(files)'
>>>
>>> That shows the following error
>>>
>>> _"filename1.dta invalid name
>>>
>>> I tried using extended macro function to clean up the quotes but to no
>>> avail.
>>

*
*   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