Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Which AI LLM is suitable to Stata?

    Under the chatbot with no example, Stata trails Python by 25.5 percentage points for Claude Sonnet 4.6 and by 30.8 points for GPT-5.6 Luna. Yet Stata is the most widely used software in empirical economics (Vilhuber et al. 2020). Under the agent with no example, the gap falls to 1.3 points for Claude Sonnet 4.6 and 6.8 points for GPT-5.6 Luna.
    cited: Letting AI agents write econometric code

    eric_a_booth wrote gemini.ado which use Gemini AI directly from the Stata command line to support research, coding, and data tasks. For some reasons, gemini is prohibited here. My questions are: (1) specifically, is there any similar package as Booth's gemini in Stata? and (2) generally, which AI is most suitable to Stata as yet?
    Code:
    . gemini "tells me story about auto dataset shipping with Stata"
    gemini v2.3.4
    Consulting Gemini CLI...
    Command: gemini --yolo -p ...
    Error: Shell failed to create output file.
    r(601);

  • #2
    hi Chen Samulsion I think you'd be interested in https://www.stata.com/stata-news/new...rner-ai-tools/
    For gemini.ado - it works in my environment on Stata 19.5 and Mac OSX and Linux , but I think it's a Windows or possibly Chinese character bug (assuming you have the correct google account to run gemini CLI unrestricted or the agy fallback I included).
    As I mentioned before, these kinds of bug reports are probably best sent directly to me to diagnose iteratively with you and I've provided my contact info below, via DM, or you can submit via Github if you prefer. In short the error you show (r601) and the shell command you quoted means Gemini’s output was never captured. It's difficult to diagnose without known your OS and how you've installed gemini or agy CLI. Regardless, I’ve pushed a fix (2.3.5) to GitHub; it will reach SSC shortly too. To install it and test/diagnose, you can run this if interested:

    Code:
    net install gemini, from("https://raw.githubusercontent.com/ericabooth/Gemini-stata/main/") replace
    which gemini
    gemini "In one sentence: what is the auto dataset that ships with Stata?"
    which gemini should report version 2.3.5. This will work as long as Gemini is available where you are and you have the right account level of CLI installed (see the helpfile). If Google blocks it in your country, no Stata-side fix can get around that. Google has restricted the Gemini CLI on some account types. Free personal accounts now get “This client is no longer supported ... migrate to Antigravity”, and gemini will stop with r(498). If you see that, install Google’s Antigravity CLI (agy) and point gemini at it:
    Code:
    gemini "your question", path("full\path\to\agy") noyolo
    Run where agy in a terminal to find the path. You need noyolo because agy doesn’t accept the --yolo flag.
    If it still fails, please run this from a do-file and email me or post the full log:

    Code:
        about
    display c(os) " / " c(osdtl)
    display c(tmpdir)
    which gemini
    * 1. Can Stata's shell write a file at all?
    shell echo hi > "`c(tmpdir)'gem1.txt"
    type "`c(tmpdir)'gem1.txt"
    * 2. The same command pattern gemini 2.3.5 uses
    shell set "X=1" && call "where" gemini > "`c(tmpdir)'gem2.txt" 2>&1
    type "`c(tmpdir)'gem2.txt"
    * 3. Is the Gemini CLI found, and does it run?
    shell gemini --version > "`c(tmpdir)'gem3.txt" 2>&1
    type "`c(tmpdir)'gem3.txt"
    * 4. The exact command gemini sends
    set trace on
    set tracedepth 1
    capture noisily gemini "hi"
    set trace off
    Eric A. Booth | Sr. Researcher | Texas2036.org | www.github.com/EricABooth

    Comment


    • #3
      I cannot speak to Chen Samulsion's first question but eric_a_booth's gemni package looks great!

      To Chen's second question, I can confirm that Claude's Sonnet, Opus, and Fable models are very skilled at writing Stata and Mata code. With a $20 USD/month subscription plan through Anthropic, you have access to Claude Code, which is what I am using for the development of dwlsmv. Claude Code, with your permission, is able to run Stata, R, Python, Mplus etc. and connect to github/bitbucket with little to no fuss. It uses some combination of command line and other OS-level hooks. It's seamless. You can also have Claude Code access other LLMs.

      Note that you are not locked into Anthropic's solution. You can use the open source program Open Code or even Microsoft's VS Code with the appropriate extensions to do similar things.

      Comment


      • #4
        I agree that Claude Opus 5.5 and Fable are good. The style of coding is strongly focused on robustness, at the expense of conciseness, which is good more often than not and excesses can be remedied by competent use of do/run, include, and frames. User-written commands were largely overlooked until recently, but this has been changing somewhat. It remains important to read and understand what is being written to store it in your memory, and avoid asking the model every time you need to revise or recall what was going on, which makes the time and memory saving essentially self-limiting - you need to know a minimum of what you delegate for delegating to work, I think this is by now fairly agreed upon as a basic principal-agent issue that applies to AI too. It remains important not to over-stretch the requests, proposing intermediate steps and avenues for implementation helps - which again means you must still think about the code itself even without having to write it in details.

        I hope Stata Corp will equip the software with a co-pilot. In my opinion, the future lies in tailored, specialized LLMs good at specific problems and their associated lexicon, not general-purpose attractions you can chat with about everything - that's humans' business. That may cost some scale economies in hardware, but I'm not sure. It will also bring to the forefront the real social and ethical question - what do we want to automatize more, and what we want to keep for ourselves to enjoy practicing.
        I'm using StataNow/MP 18.5

        Comment


        • #5
          Well said, Matteo Pinna Pintor. I find that the strengths of the LLMs in mathematics and coding are very well-suited to statistics package creation, whether that be in Stata/Mata, R, Python, or Julia. As a non-programmer, I always had to wait for someone else (including Stata Corp) to develop a package to do something that I wanted from the software. This was frustrating because not everyone is interested in the things I think are important. With these tools, I can now create the packages I always wanted and make them behave the way I think they should. There is still a lot of time and effort involved by the human software engineer or orchestrator to build these things, but I find the effort enjoyable.

          Comment


          • #6
            Erik Ruzek and Matteo Pinna Pintor, thank you both for sharing—I found these perspectives very valuable. Erik Ruzek's shift "from waiter to creator" struck me. I think I've learned more in the AI era than ever before, and faster too (setting aside the age factor—that is, the fact that one's mental faculties are not what they used to be as one gets older).

            I think Matteo Pinna Pintor's principal–agent framing captures the core of AI-assisted programming: AI lowers the cost of execution, not the cost of judgment. I particularly agree that "even without having to write the code in detail, you still have to think about the code itself." It's a bit like statistical software: you type a command, it returns a result quickly, but you bear the responsibility of interpreting that result. If anything has changed in the AI era, I think it is this: you can now ask AI not only to run commands but also to interpret the statistical results—and that, in a sense, raises the bar for humans rather than lowering it, because you now take on the additional responsibility of judging whether the AI's interpretation is right.

            Back to the point: many thanks to eric_a_booth for the help. The reason I can't use Gemini is actually quite simple and quite cruel: I can't log in to Google properly here, nor can I register an account. In fact, I followed Eric's instructions in the help file for the gemini command step by step and completed the installation, but I couldn't go any further at the final step, namely "log in to your Google account and authorize the CLI." The following are the full logs generated based on Eric's prompts (I have redacted my Stata perpetual license).

            Code:
            . about
            
            Stata/SE 16.0 for Windows (64-bit x86-64)
            Revision 26 Jun 2019
            Copyright 1985-2019 StataCorp LLC
            
            Total physical memory:       16.00 GB
            Available physical memory:    7.05 GB
            
            . display c(os) " / " c(osdtl)
            Windows / 64-bit
            
            . display c(tmpdir)
            C:\Users\chen_\AppData\Local\Temp/
            
            . which gemini
            c:\ado\plus\g\gemini.ado
            *! version 2.3.4  09nov2026
            *! Eric A. Booth
            
            . * 1. Can Stata's shell write a file at all?
            . shell echo hi > "`c(tmpdir)'gem1.txt"
            
            . type "`c(tmpdir)'gem1.txt"
            hi 
            
            . * 2. The same command pattern gemini 2.3.5 uses
            . shell set "X=1" && call "where" gemini > "`c(tmpdir)'gem2.txt" 2>&1
            
            . type "`c(tmpdir)'gem2.txt"
            C:\Users\chen_\AppData\Roaming\npm\gemini
            C:\Users\chen_\AppData\Roaming\npm\gemini.cmd
            
            . * 3. Is the Gemini CLI found, and does it run?
            . shell gemini --version > "`c(tmpdir)'gem3.txt" 2>&1
            
            . type "`c(tmpdir)'gem3.txt"
            0.68.0
            
            . * 4. The exact command gemini sends
            . set trace on
            
            . set tracedepth 1
            
            . capture noisily gemini "hi"
              ----------------------------------------------------------------------------- begin gemini ---
              - version 16.0
              - syntax [anything(name=query)], [CSV JSON Clear PATH(string) MODEL(string) NOYOLO]
              - display as text "gemini v2.3.4"
            gemini v2.3.4
              - local iswin = (c(os) == "Windows")
              - mata: st_local("isempty", strofreal(strtrim(st_local("query")) == ""))
              - if `isempty' {
              = if 0 {
                display as error "Please provide a search query."
                exit 198
                }
              - if "`csv'" != "" & "`json'" != "" {
              = if "" != "" & "" != "" {
                display as error "options csv and json may not be combined"
                exit 198
                }
              - local gemcmd "gemini"
              - if `"`path'"' != "" local gemcmd `"`path'"'
              = if `""' != "" local gemcmd `""'
              - else {
              - if !`iswin' {
              = if !1 {
                capture confirm file "/opt/homebrew/bin/gemini"
                if _rc == 0 local gemcmd "/opt/homebrew/bin/gemini"
                else {
                capture confirm file "/usr/local/bin/gemini"
                if _rc == 0 local gemcmd "/usr/local/bin/gemini"
                }
                }
              - }
              - local yolo = cond("`noyolo'" == "", "--yolo", "")
              = local yolo = cond("" == "", "--yolo", "")
              - local datamode = cond("`csv'" != "", "csv", cond("`json'" != "", "json", ""))
              = local datamode = cond("" != "", "csv", cond("" != "", "json", ""))
              - tempfile rawout rawerr rawst
              - local outfile : copy local rawout
              - local errfile : copy local rawerr
              - local stfile : copy local rawst
              - mata: _gemini_cmd(`iswin')
              = mata: _gemini_cmd(1)
              - display as text "Consulting Gemini CLI..."
            Consulting Gemini CLI...
              - mata: display("Command: " + st_local("dispcmd"), 1)
            Command: gemini --yolo -p ...
              - shell `macval(shcmd)'
              = shell ""gemini" --yolo -p "Query: hi. " > "C:\Users\chen_\AppData\Local\Temp\ST_2ef4_000001.
            > tmp" 2> "C:\Users\chen_\AppData\Local\Temp\ST_2ef4_000002.tmp" && (echo 0)> "C:\Users\chen_\Ap
            > pData\Local\Temp\ST_2ef4_000003.tmp" || (echo 1)> "C:\Users\chen_\AppData\Local\Temp\ST_2ef4_0
            > 00003.tmp""
              - capture confirm file "`outfile'"
              = capture confirm file "C:\Users\chen_\AppData\Local\Temp\ST_2ef4_000001.tmp"
              - if _rc {
              - display as error "Error: Shell failed to create output file."
            Error: Shell failed to create output file.
              - exit 601
                }
              ------------------------------------------------------------------------------- end gemini ---
            
            . set trace off

            Comment


            • #7
              Hi Chen Samulsion , thanks for clarifying where you got stuck. Are there any other LLMs you can already access from your Windows machine, such as DeepSeek or Qwen? Would running a model locally with Ollama also be an option for you? Once the model is downloaded, you can run it without signing in to an external account.

              Are you mainly looking to ask questions from inside Stata, as with gemini.ado, or would a tool that runs alongside Stata and can work with your do-files also suit you?

              Comment


              • #8
                Thank you, Choonjoo Lee. Back to the starting point of this thread, DeepSeek is currently imposing severe rate limits, and it is said they are planning to abandon consumer-facing users. My original thought was to ask whether there exists an AI that can replace DeepSeek and is particularly well-suited for Stata; Eric's gemini.ado is what I found in my search, but unfortunately I can't use it here.I also have used Ollama for local deployment and have installed qwen3.5:4b, gemma4:12b, and gemma3:12b, but they run very slowly—a simple question takes tens of seconds or even several minutes to think about, and the usability of the results is also quite poor. I have now installed DeepSeek Harness and may consider purchasing tokens.

                Comment


                • #9
                  Thanks, Chen Samulsion . Your experience with Ollama is helpful. Given the response times and results you saw, Kimi Code and Qwen Code with Alibaba Cloud Model Studio might be worth trying, if either is available to you. I haven’t compared them on Stata tasks, so I’d treat them as candidates to test.

                  Since you already have DeepSeek Harness installed, it could serve as a baseline. One simple test would be to give each tool the same Stata 16 do-file with an error you can reproduce. Ask it to fix the error, run the file, and explain what the Stata log shows. That would give you a practical sense of which tool gets the result right, how long it takes, and how much help it needs from you.

                  If you try Harness, I’d be interested to hear whether it can run your local copy of Stata and revise the do-file based on the log.

                  One idea, if you try DeepSeek Harness, would be to keep a small project notebook of Stata problems you’ve already solved. For each case, you could save the Stata version, the error, a minimal do-file, the fix that worked, and the relevant lines from the log. A short instruction in AGENTS.md could tell the harness to consult those notes when it encounters a similar problem. You could carry the same notes over if you decide to try another agent.

                  A more experimental extension would be to use ideas from ACT-R or Soar to retrieve relevant cases automatically. For example, the Stata version and error code could serve as cues for recalling a previous fix and the check that confirmed it. I’d be curious whether that helps the agent solve recurring problems in fewer attempts.

                  For anyone interested in the cognitive architectures I mentioned, here are their official project sites.

                  ACT-R (Carnegie Mellon University)
                  Soar (University of Michigan)

                  Both offer ideas for organizing and retrieving past experience. In the Stata example, the question would be whether an agent can use cues such as the Stata version, command, and error code to retrieve a relevant, previously verified fix.

                  Comment


                  • #10
                    Chen, another idea would be to use the Stata and Mata manuals as a tutor for the agent. The manuals that ship with your version of Stata give us a good starting point because they document the syntax, options, and worked examples for the software you actually run.

                    A small experiment could use two agents. One would pick a manual entry and turn it into a practical question. The other would look up the relevant section, write a short do-file, and run it in Stata 16. The first agent would then check the resulting log against the expected result. We could save each verified case with the Stata version, the manual entry, the working code, and the check that passed.

                    That would also give us a concrete way to explore ACT-R or Soar. When a similar task comes up again, a production rule could fire and retrieve a verified case using cues such as the Stata version, the command, and the error code. The case would give the agent a tested starting point for the new task.

                    I’d start with questions that have documented answers and compare the same model with and without access to the version-matched manual and the verified cases. Does it get more answers right? Does it need fewer attempts? Does it solve the problem faster overall? For a new estimator or algorithm, the manuals could still help us check the Stata and Mata building blocks while we work out the method ourselves.

                    Stata PDF documentation
                    ACT-R
                    Soar

                    Comment


                    • #11
                      Dear Choonjoo Lee, thank you very much. I will consider your suggestion, and use experiences you gives above. If consumer-facing users is really to be abondoned in their plan, I should put the buildings of agent on my agenda seriously.

                      Comment

                      Working...
                      X