Announcement

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

  • Mouseless Stata use

    I don't like taking my hands off of my keyboard to use my mouse, because I want maximal efficiency in computer usage. Outside of Stata, I use Vimium for Chrome, and I make extensive use of keyboard shortcuts. But Stata itself is very mouse-dependent, which is a source of constant frustration.

    What keyboard shortcuts or other hacks do you use to reduce your mouse usage in Stata?

  • #2
    I completely agree, it’s just generally frustrating having to use the mouse. I’m not sure how to go about this answer systematically, so here is something that at best resembles a stream of consciousness.

    I usually Alt + Tab back and forth between my Do-file editor (which you can open with Ctrl + 9) and the result window in Stata. You can highlight script lines using Shift + Arrow Keys and execute the highlighted lines with Ctrl + D. Switching to the result window puts the cursor in the command line where I often use -browse- to open up the dataset window. I then close it again using Alt + Space + C. Back in the command line you can use Ctrl + R to call back the latest command into the command line, or you can hold Ctrl and press R multiple times to cycles through the nth latest command executed (alternatively, PgUp and PgDn has the safe functions). The -help- command is cool to call up documentation windows, which I can close again using Alt + Space + C.

    I think these are my standard cycles, and now that I think about it, I don’t really find that I have to resort to the mouse at often actually. I guess when I use the mouse the most is when scrolling up and down, either in the result window or in the Do-file editor.

    I’m not sure this will help you at all, but anyway, that’s my use of the keyboard in Stata. I guess the best advice is not to use the point and click interface at all, but strictly reply on the command line and the Do-file.

    PS. You can check out the Stata manual on keyboard use here: http://www.stata.com/manuals13/u10.pdf

    // Mathias

    Comment


    • #3
      I hate to sound like a real old time person (I started doing statistical analysis on mainframes with punch cards) but if you are doing something important you should use a .do file (with lots of comments). It's OK to try a few things pointing and clicking but you need to have explicit documentation for what you do and that can only be done with a .do file. Sorry to sound like a jerk but it's true..

      Comment


      • #4
        I don't use the do-file editor, because like most modern editors it assumes I want to drag my hand around on the desktop. Get a keyboard oriented editor and just alt-tab over to Stata when you want to run the file. I use -vim- ( a Windows port of the unix workhorse -vi-) which is distributed with Stata syntax highlighting for extra productivity; others may have other editor suggestions.

        hth,
        Jeph

        Comment


        • #5
          Originally posted by Jeph Herrin View Post
          I don't use the do-file editor, because like most modern editors it assumes I want to drag my hand around on the desktop. Get a keyboard oriented editor and just alt-tab over to Stata when you want to run the file. I use -vim- ( a Windows port of the unix workhorse -vi-) which is distributed with Stata syntax highlighting for extra productivity; others may have other editor suggestions.

          hth,
          Jeph
          What in the dofile editor requires you to use your mouse?

          Comment


          • #6
            I love Notepad++ which I use for other languages, for instance Python, and I recently tried using it as my Stata editor. What annoys me about using a third party editor is that you'd have to manually update the XML-file containing word classes whenever you decide to install a new user written package in Stata. For instance if I want the editor to recognize that -putexcel- is a is a certain calls of command (thus highlighting it in a certain color), I would have to add the command in Notepad++ manually. Do you guys have any thoughts on this?

            Comment


            • #7
              Originally posted by Mathias Pedersen Heinze View Post
              I love Notepad++ which I use for other languages, for instance Python, and I recently tried using it as my Stata editor. What annoys me about using a third party editor is that you'd have to manually update the XML-file containing word classes whenever you decide to install a new user written package in Stata. For instance if I want the editor to recognize that -putexcel- is a is a certain calls of command (thus highlighting it in a certain color), I would have to add the command in Notepad++ manually. Do you guys have any thoughts on this?
              In Stata user written commands don't get highlighted either, so it's already an improvement I suppose.

              Comment


              • #8
                Originally posted by Jesse Wursten View Post

                In Stata user written commands don't get highlighted either, so it's already an improvement I suppose.
                Oh yeah, your're right. Don't know why I had this idea in my head.

                Comment


                • #9
                  I have to agree with the other posters in that it's quite possible to do almost everything without the mouse. On my system after starting Stata, I hit Ctrl+9 to open the do-file editor, and then Alt+Tab between the two windows. When I wish to run some code, I can either type it directly into the Stata command pane or highlight the relevant do-file lines and hit Ctrl+D to execute just those lines. If you don't highlight any lines in the do-file editor and hit Ctrl+D, then Stata will try to execute the whole do-file. In my opinion, the amount of syntax highlighting provided by the editor is sufficient for whatever I code that I don't feel the need to use another code editor (my favourites are Notepad++ or SublimeText).

                  There is much time to be saved by knowing only a few keyboard shortcuts with Stata.

                  Comment


                  • #10
                    Originally posted by Jesse Wursten View Post

                    What in the dofile editor requires you to use your mouse?

                    There's no requirement, sure. And a lot of the advantage of -vi- depends on knowing how to use regular expressions. But I can easily select, move, copy, find, paste, duplicate, substitute and otherwise manipulate either words or lines without reaching for the mouse. This is because -vi- has two modes, edit and insert, and in edit mode I can use single keystrokes to hop between tokens and lines, to find the next occurrence of a word, or to make substitutions using regular expressions.Then with a single keystroke, I switch to insert mode and what I type goes into the text; hit escape, and I'm back in edit mode. The dofile editor has nothing remotely comparable.


                    Comment


                    • #11
                      Originally posted by Jeph Herrin View Post


                      There's no requirement, sure. And a lot of the advantage of -vi- depends on knowing how to use regular expressions. But I can easily select, move, copy, find, paste, duplicate, substitute and otherwise manipulate either words or lines without reaching for the mouse. This is because -vi- has two modes, edit and insert, and in edit mode I can use single keystrokes to hop between tokens and lines, to find the next occurrence of a word, or to make substitutions using regular expressions.Then with a single keystroke, I switch to insert mode and what I type goes into the text; hit escape, and I'm back in edit mode. The dofile editor has nothing remotely comparable.

                      Can't most of these things be accomplished using ctrl + H / ctrl + F / pageup and so on? Perhaps not as smoothly as in -vi-, but the functionality is largely there.

                      Comment


                      • #12
                        You can always add your own shortcuts with the profile.do. When you invoke Stata it runs the commands in the profile.do file located in the Stata installation directory. For example you can open do file once and name it as profile.do on this do file you can add all of your shortcuts such as the following line:
                        Code:
                        global F6 = "save, replace"
                        After you save the profile.do and rebooting your Stata , the results window will list ‘running C:\data\profile.do ...’, now press F6 to print in the command line the command "save, replace" you can do this for almost all commands. I think it can also save some of your mouse use.

                        Comment


                        • #13
                          Originally posted by Jesse Wursten View Post

                          Can't most of these things be accomplished using ctrl + H / ctrl + F / pageup and so on? Perhaps not as smoothly as in -vi-, but the functionality is largely there.

                          For example, in -vi- if I want to delete 3 words starting at the cursor, I type "3dw", and I'm done. If I jump down a few lines, I just use "p" to paste them back. If I want to substitute all occurrences of "up" with "down" on the current line, I just type "s/up/down/g"; if the first occurrence on this and the next 6 lines, I just type ".,6+s/up/down/". There are also single key strokes for copying and pasting lines, or fragments of them: "Ykp" (yank, up, put) will copy the current line, move me up one line, then paste it in, or I can delete 5 lines, go down 10, and paste, with 5dd 10jp.

                          Yes, I can do all of those things with keystrokes in the do-file editor, but I'd say the difference in "smoothness" is qualitative, not quantitative.

                          Comment


                          • #14
                            Originally posted by Jeph Herrin View Post


                            For example, in -vi- if I want to delete 3 words starting at the cursor, I type "3dw", and I'm done. If I jump down a few lines, I just use "p" to paste them back. If I want to substitute all occurrences of "up" with "down" on the current line, I just type "s/up/down/g"; if the first occurrence on this and the next 6 lines, I just type ".,6+s/up/down/". There are also single key strokes for copying and pasting lines, or fragments of them: "Ykp" (yank, up, put) will copy the current line, move me up one line, then paste it in, or I can delete 5 lines, go down 10, and paste, with 5dd 10jp.

                            Yes, I can do all of those things with keystrokes in the do-file editor, but I'd say the difference in "smoothness" is qualitative, not quantitative.
                            Oh wow, that is something different entirely indeed. It would indeed be nice to have such functionality in the dofile editor...

                            Comment


                            • #15
                              Message for Michael Wiebe.

                              I don't have much helpful to say, but I sympathize with your position greatly.

                              The following might be a little helpful.

                              Before the final do-file is created, that has the exact archive of what has been done to create the file that will be saved for archival purposes / 100% replication records, I do the following.

                              I have two do-files open, and I go between them using "control + tab."

                              Do-file #1 is the "permanent" do-file that is being worked on. I take a chunk of code out of that do-file, and put it in the second do-file. Right before the chunk of code that is taken out, in do-file #1, a command saves the file I'm working on (often with a temporary name).

                              Do-file #2 has the chunk of code that I'm currently working on. When I run it, I merely have to press "control + d" and it runs the entire chunk.

                              (Obviously, at the top of do-file #2 are the commands "drop _all" followed by another command opening the file saved at the end of the portion of code in do-file #1 that precedes the chunk of code temporarily put into do-file #2. There may be other obvious things I'm leaving out to make this system work.)

                              I alter the code in do-file #2 over and over as I'm working on it and run it dozens of times.

                              Obviously, only running the chunk of code in do-file #2 saves me from having to wait for the earlier code to run.

                              But that could be achieved by highlighting and pressing "control d" right? The method outlined above allows me to not have to highlight the chunk of code I'm currently working on when I only want to run the portion of code in question. That is a huge time savings.

                              The problem with the method outlined above is that I have to keep moving the code back and forth between the two do-files, but the cost is outweighed by the benefit.

                              The following built-in Stata keyboard shortcut would help immensely.

                              It would run the do-file from

                              -the first line of code that was used last time code was run

                              -to the line where the cursor currently is.

                              I wouldn't need to have two do-files open in that case.

                              Is there such a command like that now?

                              Michael Wiebe, I tried to find your email address to discuss the topic you raised, but couldn't easily find it. Email me if you'd like, I'm pretty easy to find.

                              Carl

                              Comment

                              Working...
                              X