Using TextPad with Stata
This site contains a summary of tips concerning the use of the texteditor TextPad with Stata. Most of the solutions and tips are collected through the Statalist and other web-based discussions of the topic. Thus, I do not claim to be the original contributor of any of the tips on this web-page. I would like to give credit where credit is due but I am afraid I have not kept any references.
TextPad makes this easy, given that there is already a file available for download at www.textpad.com which will provide this feature. Download the file stata.syn (link provided in the columns to the left) to the directory TextPad \ Samples, usually located in your Program Files-directory. Two steps are needed in TextPad to activate highlighting. First we need to associate Stata-files with TextPad. Open the menu Configure, choose the item New Document Class. This brings up the following dialog box:
Pressing Next takes you to a box where you are supposed to add the file-extensions for Stata files. To add do and ado-files write *.do,*.ado in the field.
Next takes you to yet another dialog box (below) . Tick the Enable syntax highlighting-box and choose the stata.syn file. Click next and finish, do and ado files will now appear in various colours.
Like most editors TextPad allows the users to define tools that run other programs and pass arguments and files to these programs. To add Stata choose Configure->Preferences, go to Tools and click add. Browse to the Stata executable and select it. You will need to change some parameters in order for Stata to run properly. As seen below the switch /e is needed to run the do file currently active in TextPad. The /k option sets memory.
Next we have to assign a Tool-icon to this command. As in most programs, TextPad included, this is easily done by right-clicking the toolbar, selecting customize->Commands and then adding the correct icon among the other tool-icons. If you hover the mouse-pointer over the 'hammers' the function assigned to the icons will eventually reveal itself. Move the Stata tool to the TextPad-toolbar. When you click this tool an instance of Stata will run in the background, i.e. you will not be able to run the file in an open Stata-session. The output can be captured with a log-file.
Note: TextPad will also capture the output, and save it to a log-file. If your do-file is called myfile.do, TextPad will capture the output in myfile.log. If you choose to open your own log-file within the do-file, remember not to name it myfile.log, or both Stata and TextPad will write to the file, making it a complete mess.
In the preference menu you may look at other options, for instance File which will enable automatic log-file reloading. Keep both do and log-files open and track the progress. This way you can simulate the behaviour of the program TSP (through the Looking Glass).
This trick will not simulate Stata's inbuilt editor's way of passing selected text to Stata. So passing a selection will require more than one keypress/mouse-click. The trick is taken from a news-group. It involves saving the selected text to a do file, switching to Stata and running the do-file from there. This operation can be made quite painless by defining a macro in TextPad which saves a do-file (with the selected text) with a particular name to a particular directory. For instance saving a file, _selection.do, to C:\Data. Defining macros in TextPad can be done just as easily as in Word. Select some text, start recording the macro (Macros->Record), choose Save As in the File-menu, tick the save selection button and save. Stop the macro-recording and give the macro some name.
This macro can be assigned to a key. In Configure->Preferences->Keyboard you have the option to assign keys to commands, macros included. To ease the operation from Stata, the running of this particular do file may be assigned to a key. I have configured this behaviour in profile.do which is placed in Stata's default directory. My profile-file looks like this:
global F1 "do I:\work\Del\_merket;"
When I want to run a selection from TextPad I mark the text, hit F1 in TextPad, use alt-tab to find Stata and hit F1 once more when I am there. Too many key-presses? Well, I do not think so.
I often run my Stata-jobs on mainframe Unix-computers. Unfortunately I have no access to these computers through the Samba (SMB) interface (no mapped drive). Originally I had two choices in pratice when it came to editing do-files. One was to edit files on my Windows-workstation, send these to the Unix-computer using scp, sftp or other transfer-protocols and finally running/queueing them. Another way was to edit the files using Unix-editors like emacs and vi. Given that my emacs/vi-skills were, and still are, very limited I opted for a better solution. I wanted to edit the files on my favourite windows-based editor and easily send them to the unix-computer. The solution I came up with was to configure TextPad (should be possible in other editors as well) to send my do-file to the mainframe using the free downloadable program pscp.
I added pscp as a new tool with the relevant parameters, and assigned a tool button to it. With a click of this button my do-file is transferred to the unix-computer. As seen below pscp takes the password as an argument. This obviously raises concerns over security. The use of this procedure should therefore be restricted to computers with restricted accsess, i.e. (correctly configured) computers running win NT / 2000 or XP pro.
The use of password-identification could be avoided if one implemented a public key identification scheme. Take a look at OpenSSH on Windows. This page offers a free SSH-server for win NT/2000