Announcement

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

  • Using stata via VS Code

    Dear Stata users,
    I was wondering what options one has to run stata from VS Code. I know of the following and was wondering whether I'm overlooking something.
    Any help is much appreciated! If you are using one of these solutions, it would be nice to know whether you have any small hacks that improve the experience. Thank you
    Last edited by Max Bruening; 11 Mar 2024, 09:44.

  • #2
    +1 to this request. I have for a long time wished for


    Official or semi-official plugins for popular text editors (VSCode, Notepad++, Sublime, etc) -- there are some nice user-written contributions but official versions (or still user-written but with active help from StataCorp) with one-click installation would be a huge improvement. Even just providing a single place to look for authoritative information would be great.

    Comment


    • #3
      Not sure about efficiency,
      But lately i have been using vscode with nbstata (another Stata Kernel) for making slides with Stata Code. It seem to work well now, because VSC also opens a live Jupyter Stata notebook. I combine this with quarto for some fancy output.
      Im also trying to put together the Stata Journal Format as a Quarto Journal for easier writing, and hopefully encapsulated replication code.
      F

      Comment


      • #4
        Even though this thread is a bit older the below may still be useful.

        I just set up calling Stata from VS Code using the Code Runner extension in combination with Friedrich Hübler's well known AutoIt programs for calling Stata from external editors. This description helped me in the process. Accordingly, I added the following entries to the VS Code settings.json file:
        Code:
            "code-runner.executorMapByFileExtension": {
                ".do"   : "\"C:\\some path\\rundo.exe\"",
                ".mata" : "\"C:\\some path\\rundo.exe\""
            },
            "code-runner.customCommand": "\"C:\\some path\\rundolines.exe\""
        I then assigned custom shortcuts for either running the whole file (Run Code command) or selected lines (Run Custom Command command). Code Runner's defaults for these are ctrl+alt+N and ctrl+alt+K, respectively.

        I only discovered later that a similar procedure had already been documented in more detail in a former post on the Stata Forum. The post points to a detailed description of the procedure located on a GitHub site. There, the entries in the settings.json file follow a different strategy and hence differ. Either way works fine, I think.

        As a disclaimer, I'd like to add that I am not using Code Runner in other respects and have no experience with it, so the above settings may well be at odds with other purposes of using the extension. Moreover, I have only tried out calling Stata a couple of times but have not worked with / tested this mechanism over a longer period of time.

        If you are using some of the above, you may want to switch off Code Runner's telemetry in the settings.

        Comment


        • #5
          Maybe others have had more success, but I can't get this - CodeRunner with Hubler's AutoIt programs - to work. CodeRunner passes the instructions to rundo.exe which starts Stata. This runs my profile.do program and then hangs. Even if Stata is running what the program does it to start a new instance of Stata that there is no difference between the outcome in either case. I am used to running Stata in batch mode but rundo doesn't appear to pass the instruction to run the do file to Stata. I have tried this with Stata 17 and 18.5. It is supposed to work with Stata 17 at least.

          Comment


          • #6
            Gordon, these instructions from Sook Kim here https://github.com/sook-tusk/Tech_In...tors/tree/main helped me link VS Code to Stata. Since I am using StataNow, I made the following changes in rundolines.ini
            statapath = "C:/Stata18/StataMP-64.exe"
            statawin = "StataNow/MP 18.5"

            Comment

            Working...
            X