how to use Stata in Emacs (with ess)

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

how to use Stata in Emacs (with ess)

ollie_m
This post was updated on .
I'm trying to run Stata do-files in the Emacs editor, and I have already installed the ESS package (actually I installed a modified Emacs with ess built in, as recommended for Windows users in the ess installation manual.).

Now when I open up an do-file, the syntax is properly highlighted, the mode is show as (ESS [sta]), but I just have no clue how to run the do-file (the chosen line or the whole do-file), and how to see the results.

I have been googling for quite a while and haven't found any thing about it yet, and the ESS package manual has turned out to be the most esoteric user manual I have ever read.

In the ESS manual, it says that to start a process, I should M-x stata, then Emacs would prompt me a question "Starting data directory?"

What exactly is this directory? is it where Stata is installed? is it where my do-file is located? or is it where my .dta files are? I certainly have no .Data file..

when I tried to run the do-file (C-c C-b), Emacs told me "Searhing for program: no such file or directory, stata". so I guess Emacs is having some difficulty finding where my Stata is installed. How can I fix this?


I'm using windows 8, in my user directory, under ~/.emacs.d/ folder, I have no .emacs or init.el file.
Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

Vitalie Spinu-2

>> On Wed, Sep 09 2015 00:10, ollie_m wrote:

> In the ESS manual, it says that to start a process, I should M-x stata, then
> Emacs would prompt me a question "Starting data directory?"

It's the directory where to run stata process. That is your working
directory. You start with M-x stata and it should open a buffer with the stata
process. You can use that buffer like any other comint buffer in emacs.

>From do files you will be able to send paragraphs (C-c C-c) and load those files
into that stata sub-process (C-c C-l) among other things.

> What exactly is this directory? is it where Stata is installed?

No. This is your working directory with your stata do files.

> when I tried to run the do-file (C-c C-b), Emacs told me "Searhing for
> program: no such file or directory, stata". > so I guess Emacs is having some
> difficulty finding where my Stata is installed. How can I fix this?

The stat program name is configured in inferior-STA-program-name variable which
is by default "stata". So, either you should point that variable to stata
process. Or add the directory with your stata.exe to your Path variable and
restart emacs.


  Vitalie

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help
Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

ollie_m
Vitalie Spinu-2 wrote
The stat program name is configured in inferior-STA-program-name variable which is by default "stata". So, either you should point that variable to stata process. Or add the directory with your stata.exe to your Path variable and restart emacs.
Hi Vitalie, Can you give me some detail on how to point the variable inferior-STA-program-name to the stata process?

As I understand it, the value of the inferior-STA-program-name variable should be the name of the Stata program, so I changed the variable name to StataSE, and I added my Stata program folder (D:/Programs/Stata) to the system path.

Now when I highlight some lines and C-x C-r, Emacs, like always, asks me "Starting data directory?" after I give it my directory, instead of running the code in Emacs, it starts my Stata (in its own window) and does nothing, and Emacs freezes and I have to force close the window.

Where did I go wrong?

Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

Vitalie Spinu-2

>> On Wed, Sep 09 2015 05:09, ollie_m wrote:

> Vitalie Spinu-2 wrote
>> The stat program name is configured in inferior-STA-program-name variable
>> which is by default "stata". So, either you should point that variable to
>> stata process. Or add the directory with your stata.exe to your Path
>> variable and restart emacs.

> As I understand it, the value of the inferior-STA-program-name variable
> should be the name of the Stata program, so I changed the variable name to
> StataSE,

I am not sure this is the right thing. I am not a stata user so I don't know.

The program that you pointed to should be runnable in terminal. If you can run
StataSE in terminal, you should (in principle) be able to run it inside emacs.

> and I added my Stata program folder (D:/Programs/Stata) to the system path.

You could have simply set inferior-STA-program-name to the full path like
D:/Programs/Stata/stata without adding the directory to the path.

> Now when I highlight some lines and C-x C-r, Emacs, like always, asks me
> "Starting data directory?" after I give it my directory, instead of running
> the code in Emacs, it starts my Stata (in its own window) and does nothing,
> and Emacs freezes and I have to force close the window.

You are almost there. Before running any code you need to start an inferior
process such that ESS can communicate with it. This is why you are asked for the
directory when you evaluate the code for the first time.

The problem is that you seem not to be running the right program.

Open emacs shell (M-x shell) then look for other executables in the stata folder
and try to run those inside the shell. Whichever works, point
inferior-STA-program-name to it and you should be fine.


  Vitalie

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help
Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

ollie_m
I've deleted the Stata directory from system path and changed the variable name to the full path for the executable, and I've deleted all other possible executables except stata.exe in the folder, the problem persists..

I'm not sure this is by any means related, but when I started emacs, first a black window (like a command window, with nothing but a cursor in it) pops up, then the emacs window; is emacs supposed to work this way on Windows? I've never given it any thought before, but now that I'm having this problem, this whole thing looks pretty damn suspicious.. If one window can pop up when I'm running emacs, it seems quite likely another will pop up when I'm trying to run another executable in to..
Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

Vitalie Spinu-2


>> On Wed, Sep 09 2015 06:45, ollie_m wrote:

> I've deleted the Stata directory from system path and changed the variable
> name to the full path for the executable, and I've deleted all other
> possible executables except stata.exe in the folder, the problem persists..

You don't need to delete any executables. That begs for problems.

Have you run it in shell as I suggested?

> I'm not sure this is by any means related, but when I started emacs, first a
> black window (like a command window, with nothing but a cursor in it) pops
> up, then the emacs window; is emacs supposed to work this way on Windows?
> I've never given it any thought before, but now that I'm having this
> problem, this whole thing looks pretty damn suspicious.. If one window can
> pop up when I'm running emacs, it seems quite likely another will pop up
> when I'm trying to run another executable in to..

This seems unrelated.


  Vitalie

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help
Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

ollie_m
sorry I have to run some errands the last two days so I didn't have time for the problem.

I use the shell to check for the executables, stata.exe is the only one.

But I did find some thing I think might be the problem. In the ESS manual, it says if I use Cygwin bash shell, I should run M-x S RET. but I'm using MSDOS prompt shell, so I should run something like M-x S+6-msdos RET.

what's the proper syntax for running a stata process? I tried M-x stata-msdos RET, M-x sta-msdos, and M-x Stata-msdos, none of them works.

Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

Sparapani, Rodney
In reply to this post by ollie_m
> sorry I have to run some errands the last two days so I didn't have time for
> the problem.
>
> I use the shell to check for the executables, stata.exe is the only one.
>
> But I did find some thing I think might be the problem. In the ESS manual,
> it says if I use Cygwin bash shell, I should run M-x S RET. but I'm using
> MSDOS prompt shell, so I should run something like M-x S+6-msdos RET.
>
> what's the proper syntax for running a stata process? I tried M-x
> stata-msdos RET, M-x sta-msdos, and M-x Stata-msdos, none of them works.

Hi Ollie:

There is the rub.  emacs and ESS are designed to work with
applications that you can launch from the command line like *shell* or
S+.  If you can launch stata.exe in a terminal window like cmd.exe and
work with it WITHIN the terminal window, then it will have a chance to
work with emacs/ESS.  That is the way Stata works on Linux.  However,
as I recall, Stata on Windows doesn't work that way; it launches its
own environment.  If that is the case, then you are rather limited to
editing .do files in emacs/ESS and then launching them in some other
way.

Rodney

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help
Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

ollie_m
Hi Rodney, thanks for the input. If that is the case I'd be seriously barking up the wrong tree..
Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

Brendan Halpin
It's worth asking Stata Technical Support directly if there is a console
mode for Windows.

Brendan
--
Brendan Halpin, Head, Department of Sociology, University of Limerick, Ireland
Tel: w +353-61-213147  f +353-61-202569  h +353-61-338562;  Room F1-002 x 3147
mailto:[hidden email]    ULSociology on Facebook: http://on.fb.me/fjIK9t
http://teaching.sociology.ul.ie/bhalpin/wordpress         twitter:@ULSociology

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help
Reply | Threaded
Open this post in threaded view
|

Re: how to use Stata in Emacs (with ess)

Vitalie Spinu-2

If it's not possible to run stata in terminal on windows we should document this
in a prominent place.

Vitalie

>> On Fri, Sep 11 2015 17:58, Brendan Halpin wrote:

> It's worth asking Stata Technical Support directly if there is a console
> mode for Windows.

> Brendan

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help