Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Stata with MacVim


From   Phil Schumm <pschumm@uchicago.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Stata with MacVim
Date   Thu, 11 Aug 2011 12:06:22 -0500

On Aug 4, 2011, at 4:20 PM, Gabi Huiber wrote:
> The do-file bash script you suggested kind of works. Suppose I had a do-file in the Documents folder that had two lines in it:
> 
> __________do-file starts here__
> di "Hello World!"
> di "Hello Gabi."
> _____________and ends here__
> 
> Now suppose that, in terminal, I type
> 
> $ do-file Documents/hello.do
> 
> This makes Stata 12 start up with the do-file editor open with a blank do-file that is called hello.do. In the terminal window, meanwhile, I get the warning "missing value".


Hmm, I can't replicate that, though I am using Stata 11 on Snow Leopard.  For me, doing what you describe above opens Stata (if not already running) and executes the file hello.do.  I get "missing value" on stdout, but I'm guessing that this is because the method in Stata that is responding is returning id instead of void.  You get the same thing if you send a file to Stata from within AppleScript Editor.  I just set my text editor to silently drop this (sorry -- can't tell you how to do that in vim).


> The same thing happens if I edit Documents/hello.do in Vim and in command mode I type :!do-file %.


Again, this works fine for me, although I get the "missing value" return message.


> This only happens once. Subsequent calls to do-file, after Stata is running, either in terminal or in the Vim command mode, produce the "missing value" warning but have no effect on Stata, as far as I can tell.


For me, either of these (i.e., calling do-file from the shell or from within vim) continues to work repeatedly; once Stata is open, subsequent calls continue to execute the contents of the file.


> If, instead, at the terminal I type
> 
> $ do-file ~/Documents/hello.do
> 
> Then Stata will start with the do-file editor open with the correct do-file loaded. The warning message in this case is
> 
> <<class >> hello.do
> 
> The blank spaces on either side of >> are as shown above, if that matters. Again, this only happens once.


I don't see why this should be any different from


    $ do-file Documents/hello.do


and indeed, on my machine, it has exactly the same effect.

Since you are using a different OS version (Lion versus SL) and a different version of Stata, one (or both) of these are likely the cause of the differences in behavior.  What has me concerned is your apparent observation that sending a do-file to Stata 12 via an Open File Apple Event is opening the do-file in the do-file editor, rather than executing it.  If so, this represents a change in behavior from Stata 11, and will make it impossible to execute a do-file directory from your text editor (unless Stata 12 has added to its AppleScript dictionary, or unless you want to play around with scripting via the GUI).  Once I get a copy of Stata 12 (hopefully within the next few weeks), I will take a look (you can do so too, by opening AppleScript Editor and using File -> Open Dictionary...).


> I have tried other tricks too, with help from the MacVim e-mail list.  For example, one way to get Stata to open my do-file in the editor without any warning messages is to rewrite my RunIt() function as follows:
> 
> function RunIt()
>  wa
>  !rm -Rf ~/Library/Saved*/com.stata*
>  !osascript -e 'tell app "StataMP" to open "%:p"'
> endfunction


If by "warning message" you mean the "missing value" as described above, I'm not sure how this hack would eliminate that; moreover, you can use it only once (i.e., not if you want to execute another do-file once Stata is already running).

As I said, I think (though I could easily be wrong) that this may be due to the responding method within Stata being declared to return id rather than void.  In my text editor I simply discard this, but unfortunately I have no idea how you'd do this in vim.  Here's a wild guess:


    :! do-file % > /dev/null


-- Phil


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index