1

I have built the latest Emacs 26.0.50.1 on a Debian OS 8 (Jessie) that uses Linux version 3.14.5. Then I installed org-mode version 9.0.3. I want to use the proprietary data analysis and statistical software Stata version 14. I have checked that it runs alright within Emacs thanks to ESS by typing M-x stata.

However, I also want to evaluate Stata code in org-mode documents. For that I have downloaded the script ob-stata.el by Ista Zahn and I have saved it together with the other ob-sth.el files in ~/.emacs.d/elpa/org-20161224. Moreover, I have edited the entry:

(defcustom org-babel-stata-command inferior-STA-program-name
  "Name of command to use for executing stata code."
  :group 'org-babel
  :version "24.1"
  :package-version '(Org . "8.3")
  :type 'string)

to reflect my current version of Org, so this piece of code currently stands as follows in my version of ob-stata.el:

(defcustom org-babel-stata-command inferior-STA-program-name
  "Name of command to use for executing stata code."
  :group 'org-babel
  :version "24.1"
  :package-version '(Org . "9.0.3")
  :type 'string)

However, if I add (stata . t) to =org-babel-do-load-languages= as follows:

(org-babel-do-load-languages
   'org-babel-load-languages
  '((emacs-lisp . t)
    (sh . t)
    (R . t)
    (perl . t)
    (ruby . t)
    (python . t)
    (js . t)
    (haskell . t)
    (stata . t)
    (shell . t)))

I get the following message when I restart emacs:

Debugger entered--Lisp error: (void-variable inferior-STA-program-name)
eval(inferior-STA-program-name)
custom-initialize-reset(org-babel-stata-command inferior-STA-program-name)
custom-declare-variable(org-babel-stata-command inferior-STA-program-name "Name of command to use for executing stata code." :group org-babel :version "24.1" :package-version (Org . "9.0.3") :type string)
....

I have checked that the file ess-sta-d.el located in /.emacs.d/elpa/ess-20161101.215/lisp has the line (inferior-ess-program . inferior-STA-program-name) included in the definition of the variable =STA-customize-alist= as follows:

(defvar STA-customize-alist
  '((ess-local-customize-alist     . 'STA-customize-alist)
    (ess-language                  . "STA")
    (ess-dialect                   . STA-dialect-name)
    (ess-suffix                    . "ado")
    (ess-mode-editing-alist        . STA-editing-alist)
    (ess-mode-syntax-table         . STA-syntax-table)
    (ess-mode-edit                 . 'STA-mode)
    (ess-help-sec-regex            . ess-help-STA-sec-regex)
    (ess-help-sec-keys-alist       . ess-help-STA-sec-keys-alist)
    (ess-loop-timeout              . 500000 )
    (ess-object-name-db-file       . "ess-sta-namedb.el" )
    (ess-help-web-search-command   . "http://www.stata.com/search/?q=%s&restrict=&btnG=Search&client=stata&num=&output=xml_no_dtd&site=stata&ie=&oe=UTF-8&sort=&proxystylesheet=stata")
    (ess-eval-linewise-function    . #'stata-eval-linewise)
    (inferior-ess-font-lock-defaults . ess-STA-mode-font-lock-defaults)
    (inferior-ess-program          . inferior-STA-program-name)
    (inferior-ess-objects-command  . "describe\n")
    (inferior-ess-help-command     . "help %s\n") ;; assumes set more off
    (inferior-ess-exit-command     . "exit\n")
    ;; --more-- is necessary here (hangs otherwise if startup stata.msg is big)
    (inferior-ess-primary-prompt   . "[.:] \\|--more--")
    (inferior-ess-secondary-prompt . "--more--")
    (comint-use-prompt-regexp      . t)
    (inferior-ess-start-file       . inferior-STA-start-file) ;"~/.ess-stata")
    (inferior-ess-start-args       . inferior-STA-start-args)
    (ess-get-help-topics-function  . 'ess-get-STA-help-topics)
    (inferior-ess-search-list-command   . "set more off\n search()\n")
    (comment-start                . "/\* ")
    (comment-end                  . " \*/")
    (comment-start-skip           . "/\\*+ *")
    (comment-use-syntax           . t) ;; needed for multiline
    (ess-execute-screen-options-command . "set linesize %s\n")
    )
  "Variables to customize for Stata.")

From here on I am lost. I have checked the corresponding scripts for other languages and in them inferior-ess-program is also and correctly assigned to their inferior program name. I don't understand why this does not happen with Stata.

Any help is greatly appreciated! I normally use R but Stata is the industry standard in econometrics and I am bound to use it when working with colleagues.

Thank you very much, Daniel

News: Thanks to an email from Nicolas Goaziou I've managed to solve this problem. First, I've reverted to

(defcustom org-babel-stata-command inferior-STA-program-name
  "Name of command to use for executing stata code."
  :group 'org-babel
  :version "24.4"
  :package-version '(Org . "8.3")
  :type 'string)

in ob-stata.el because as Nicolas noted, package-version is used to specify when a defcustom was introduced or when its default value last changed

Then I placed

(require 'ess) 
(require 'ob-stata)

before

  (org-babel-do-load-languages
   'org-babel-load-languages
  '((emacs-lisp . t)
    (sh . t)
    (R . t)
    (perl . t)
    (ruby . t)
    (python . t)
    (js . t)
    (haskell . t)
    (stata . t)
    (shell . t)
    ))

in my init.el file.

With this setup emacs started without complaining at all. However, when I tried to run stata code in org mode gave me an error,

org-babel-get-header not defined

that is well reported here and here (recall the ob-stata.el is a fork of ob-julia.el).

So I wrote:

(let ((vars (mapcar #'cdr (org-babel--get-vars params)))) in ob-stata.el instead of the original

(let ((vars (mapcar #'cdr (org-babel-get-header params :var)))) in ob-stata.el

With all this, now stata code in org mode runs smoothly. Another issue is that export to html is alright but I have found out that neither the minted nor the listings packages in LaTeX recognize stata and so I cannot get a pdf with the code and its output... but this is another story.

Again, thank you very much, Nicolas! Daniel

closed as unclear what you're asking by Tyler, DoMiNeLa10 Apr 11 at 18:19

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Sanity check: did you evaluate (org-babel-do-load-languages ...)? Eg. by moving the point to the closing paren and pressing M-C-x? – wvxvw Jan 8 '17 at 21:00
  • Thanks @wvxvw. Yes, if I add (stata . t) to the expression (org-babel-do-load-languages ...) and I evaluate it I get nil, just like when (stata . t) is not included. Still, if I then re-start emacs with the bit (stata . t) included, I get the above mentioned error: Debugger entered--Lisp error.... Also, after re-starting emacs, if I evaluate the expression (org-babel-do-load-languages ...) I get the message Symbol’s value as variable is void: inferior-STA-program-name. – Daniel Jan 9 '17 at 9:43
  • 1
    I'm not familiar with ESS internal structure, but I'd try this: grep for this variable in ESS sources, locate the file where it is defined, then look at the bottom of this file for (provide ...) form, then try to require whatever's been provided from this file before you do anything related to org-babel. This might not be the recommended way to solve this, but it will at least solve the problem in some way, perhaps giving you more insight into how ESS is structured and what you had to (require ...) in order to have that variable defined. – wvxvw Jan 9 '17 at 10:07
  • This question needs to be cleaned up, if it's not to be closed. Please clean it up, simplifying, and move any answer part of it to an answer. If you think the question and answer are not helpful to others then please delete. Thx. – Drew Apr 11 at 18:08
0

I have modified the ob-stata.el file linked above to eliminate 3 issues:

  1. Commands are repeated in stata output
  2. Garbled output for some stata commands
  3. Added support for line continuation

These issues along with more detail about how to get Stata working in Org-mode are outlined in more detail here and the modified version of ob-stata.el can be found at this github repository.

To enable stata font highlighting for latex output do the following:

  1. ensure that you have a recent version of pygmentize (=>2.2) installed (as stata has only recently been added). If have recently installed anaconda python, you'll have it.

  2. add stata to the lexer list in your init.el (add-to-list 'org-latex-minted-langs '(stata "stata")) I know this works with minted. I don't use listings and haven't tried it.

The font highliting on the latex export side in my experience is far superior to what you get from html exporting (I believe html exporting uses ESS stata language definition files and styles rather than pygmentize). For example, for me when exporting to html:

  • I have to indent all of my stata code by a space or two to get highliting in org-src blocks for highliting to work on the first word
  • There is a hit and miss nature to what is and is not highlited, and for me it isn't possible to activate the ESS - Font Lock menu item (when editing a do file) to customize the font-lock settings for customizing this. I can do this for R.
  • Comments are not given any special fontification and even worse, words like regress in a comment will be highlited as if it was a stata command

Not the answer you're looking for? Browse other questions tagged or ask your own question.