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: Using "stata" command from Mata


From   David Bell <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: Using "stata" command from Mata
Date   Tue, 23 Oct 2012 10:34:58 +0100

Yes - thanks. I think I overcomplicated my quotations.  Simplified version works fine. Though not clear why the other version failed.

Thanks again.

David Bell

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Nick Cox
Sent: 23 October 2012 10:27
To: [email protected]
Subject: Re: st: Using "stata" command from Mata

I suspect something about your quotation marks is biting. From your example filename, it seems that you don't have spaces in your filename, in general a very good idea, in which case I guess you don't need the internal "" and given that you don't need the outermost `" "'
-- so the string is much simplified.

string scalar temp
temp = "imp excel " + this.path + this.workbook + ".xlsx"
temp
stata(temp)

That said, I've never used the -import excel- command.

Nick

On Tue, Oct 23, 2012 at 10:15 AM, David Bell <[email protected]> wrote:
> In Mata, I am writing a function to put together a string to supply to the "stata" command. It goes something like this:
> void table::read_spreadsheet()
>
> {
>                 string scalar temp
>                 temp = "`" + `"""' + "imp excel " + `"""' + this.path + this.workbook + ".xlsx" + `"""' + `"""' + "'"
>                 temp
>                 stata(temp)
>
> }
>
> I suspect there are more efficient ways of constructing "temp", but I do know that executing "stata(temp)" in interactive mode works after I have constructed it as in the second line of my code. However, when I try to execute the function as part of a program, it seems to me that "temp" is abridged to 32 characters in the "stata" command after having been listed correctly in the previous line. i.e. my output from lines 3 and 4 is:
>
>
>   `"import excel "C:\Users\DavidNFBell\Dropbox\spreadsheet.xlsx""'                                                  - output of correctly formed string
> unrecognized command:  "import excel "C:\Users\DavidNFB invalid command name                      - error message indicating failure to execute stata(temp) command
> stata():  3598  Stata returned error
>
> I would be grateful if anyone could explain this/suggest an 
> alternative
>
> David Bell
>
> --
> The University of Stirling is ranked in the top 50 in the world in The Times Higher Education 100 Under 50 table, which ranks the world's best 100 universities under 50 years old.
> The University of Stirling is a charity registered in Scotland,  
> number SC 011159.
>
>
> *
> *   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/



-- 
The University of Stirling is ranked in the top 50 in the world in The Times Higher Education 100 Under 50 table, which ranks the world's best 100 universities under 50 years old.
The University of Stirling is a charity registered in Scotland, 
 number SC 011159.


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


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