Announcement

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

  • Translate Stata-14 (utf8) do-file into Stata-13 (or earlier) do-file

    Am I correct that it is not possible to translate do-files written in Stata 14 that use umlauts (e.g. ü, ö, ä, ß) into do-files that can be read "correctly" by earlier Stata versions? I searched in vain for answers to my question in the manual and the Stata forum.

  • #2
    Is the the unicode translate command useful for that matter? Or is that only useful the other way around, meaning that OLDER files are readable in Stata14?
    Not sure.

    Comment


    • #3
      As far as I can see unicode translate is a one way road to utf8 encoding.

      Comment


      • #4
        I don't know an automated solution in Stata but you can copy and paste the code from the Stata 14 Do-file Editor to the Do-file Editor of older Stata and save the do-file from old Stata.

        Another option is to use a text editor like Notepad++. In Notepad++ you can open a Stata 14 do-file, go to Encoding - Convert to ANSI, and save the converted do-file, which can then be opened in older versions of Stata.

        Comment


        • #5

          It is possible to back-translate text files (but not (yet?) datasets). See:
          Code:
          help unicode convertfile
          Obviously this should be done in Stata 14; Stata 13 does not know of this command.

          Comment


          • #6
            Thanks for these suggestions.

            I did also experiment with Ultra-Edit (22.10) as an external editor - using AutoIt-scripts to send do-file commands to Stata. Unfortunately, this does not work any more with Stata 14. Interestingly, if I edit an utf8 do-file in UltraEdit I can insert country specific characters and use these files in Stata 14. However, sending them via AutoIt-script to Stata does not work. Any ideas?

            Comment


            • #7
              Which AutoIt scripts are you using?

              Comment


              • #8
                I am using two AutoIt scripts (originally written in 2005 by yourself), one for a selection of Stata commands and one for a complete do-file.

                For sending a selection of lines from UltraEdit to Stata I am using the compiled "rundolines.au3" as follows:
                Code:
                ; AutoIt v3 script to run Stata commands from an external text editor.
                ; Version 2.2, Friedrich Huebler (fhuebler at gmail.com), 26 September 2005.
                ; Updated by Nicholas Winter (nw53 at cornell.edu), 25 May 2005.
                ; Adapted from a script by Eva Poen (eva.poen at unisg.ch), 27 June 2004.
                ; AutoIt is available at http://www.autoitscript.com/autoit3/.
                ; The latest version of this script is at
                ; http://huebler.info/2005/20050310_Stata_editor.html.
                
                ; Declare variables
                Global $statapath, $statawin, $commands, $tempfile, $tempfile2
                
                ; NOTE: Edit $statapath and $statawin before script is compiled
                ; Path to Stata executable
                $statapath = "C:\Program Files (x86)\Stata14\StataSE-64.exe"
                ; Title of Stata window
                $statawin = "Stata/SE 14.0"
                
                ; EXAMPLE: For Intercooled Stata 8.2 delete preceding block and use commands below
                ; $statapath = "C:/Program Files/Stata8/wstata.exe"
                ; $statawin = "Intercooled Stata 8.2"
                
                ; If more than one Stata window is open, the window
                ; that was most recently active will be matched
                Opt("WinTitleMatchMode",2)
                
                ; Reduce SendKeyDelay and WinWaitDelay to speed up script
                Opt("SendKeyDelay", 1)
                Opt("WinWaitDelay", 200)
                
                ; Clear clipboard
                ClipPut("")
                ; Copy selected lines from editor to clipboard
                Send("^c")
                ; Pause avoids problem with clipboard, may be AutoIt or Windows bug
                Sleep(100)
                $commands = ClipGet()
                
                ; Terminate script if nothing selected
                If $commands = "" Then
                  Exit
                EndIf
                
                ; Create file name in system temporary directory
                $tempfile = EnvGet("TEMP") & "\statacmd.tmp"
                
                ; Open file for writing and check that it worked
                $tempfile2 = FileOpen($tempfile,2)
                If $tempfile2 = -1 Then
                  MsgBox(0,"Error: Cannot open temporary file","at [" & $tempfile & "]")
                  Exit
                EndIf
                
                ; Write commands to temporary file, add CR-LF at end
                ; to ensure last line is executed by Stata
                FileWrite($tempfile2,$commands & @CRLF)
                FileClose($tempfile2)
                
                ; Check if Stata is already open, run it if not
                If WinExists($statawin) Then
                  WinActivate($statawin)
                  WinWaitActive($statawin)
                  ; Activate Stata Command Window (Stata < 12: ^4, 12+: ^1) and select text (if any)
                  Send("^1")
                  Send("^a")
                  ; Run temporary file
                  ; Double quotes around $tempfile needed in case path contains blanks
                  ClipPut("do " & '"' & $tempfile & '"')
                  ; Pause avoids problem with clipboard, may be AutoIt or Windows bug
                  Sleep(100)
                  Send("^v" & "{Enter}")
                Else
                  Run($statapath)
                  WinWaitActive($statawin)
                  ; Activate Stata Command Window (Stata < 12: ^4, 12+: ^1)
                  Send("^1")
                  ; Run temporary file
                  ; Double quotes around $dofile needed in case path contains blanks
                  ClipPut("do " & '"' & $tempfile & '"')
                  ; Pause avoids problem with clipboard, may be AutoIt or Windows bug
                  Sleep(100)
                  Send("^v" & "{Enter}")
                EndIf
                For sending a the complete .do-file from UltraEdit to Stata I am using the compiled "rundo.au3" as follows:
                Code:
                ; AutoIt v3 script to run a Stata do-file from an external text editor.
                ; Version 2.2, Friedrich Huebler (fhuebler at gmail.com), 26 September 2005.
                ; Updated by Nicholas Winter (nw53 at cornell.edu), 25 May 2005.
                ; Adapted from a script by Dimitriy V. Masterov
                ; (dvmaster at lily.src.uchicago.edu), 23 June 2004.
                ; AutoIt is available at http://www.autoitscript.com/autoit3/.
                ; The latest version of this script is at
                ; http://huebler.info/2005/20050310_Stata_editor.html.
                
                ; Declare variables
                Global $statapath, $statawin, $dofile
                
                ; NOTE: Edit $statapath and $statawin before script is compiled
                ; Path to Stata executablee
                $statapath = "C:\Program Files (x86)\Stata14\StataSE-64.exe"
                ; Title of Stata window
                $statawin = "Stata/SE 14.0"
                
                ; EXAMPLE: For Intercooled Stata 8.2 delete preceding block and use commands below
                ; $statapath = "C:/Program Files/Stata8/wstata.exe"
                ; $statawin = "Intercooled Stata 8.2"
                
                ; NOTE: Edit this block of commands to match the editor used
                ; EmEditor or TextPad: path of do-file is passed to AutoIt
                $dofile = $CmdLine[1]
                
                ; Alternative method to obtain path of do-file with EmEditor
                ; Get path of do-file from title of EmEditor window
                ; $dofile = WinGetTitle("")
                ; Remove unwanted text from window title to keep path only
                ; $dofile = StringReplace($dofile," - EmEditor","")
                
                ; Alternative method to obtain path of do-file with TextPad
                ; Get path of do-file from title of TextPad window
                ; $dofile = WinGetTitle("")
                ; Remove unwanted text from window title to keep path only
                ; $dofile = StringReplace($dofile,"TextPad - ","")
                ; $dofile = StringReplace($dofile,"[","")
                ; $dofile = StringReplace($dofile,"]","")
                
                ; If more than one Stata window is open, the window
                ; that was most recently active will be matched
                Opt("WinTitleMatchMode",2)
                
                ; Reduce SendKeyDelay and WinWaitDelay to speed up script
                Opt("SendKeyDelay", 1)
                Opt("WinWaitDelay", 200)
                
                ; Check if Stata is already open, run it if not
                If WinExists($statawin) Then
                  WinActivate($statawin)
                  WinWaitActive($statawin)
                  ; Activate Stata Command Window (Stata < 12: ^4, 12+: ^1) and select text (if any)
                  Send("^1")
                  Send("^a")
                  ; Run saved do-file
                  ; Double quotes around $dofile needed in case path contains blanks
                  ClipPut("do " & '"' & $dofile & '"')
                  ; Pause avoids problem with clipboard, may be AutoIt or Windows bug
                  Sleep(100)
                  Send("^v" & "{Enter}")
                Else
                  Run($statapath)
                  WinWaitActive($statawin)
                  ; Activate Stata Command Window (Stata < 12: ^4, 12+: ^1)
                  Send("^1")
                  ; Run saved do-file
                  ; Double quotes around $dofile needed in case path contains blanks
                  ClipPut("do " & '"' & $dofile & '"')
                  ; Pause avoids problem with clipboard, may be AutoIt or Windows bug
                  Sleep(100)
                  Send("^v" & "{Enter}")
                EndIf

                Comment


                • #9
                  The current rundo and rundolines scripts don't support Unicode. As it happens, I have been working on versions that will support Unicode and may post them on my website as early as today. I will write again when the updated scripts are available.

                  Comment


                  • #10
                    An updated version of the rundo and rundolines programs with Unicode support is now available. The purpose of these programs is to facilitate the integration of external text editors with Stata. Many thanks to Dirk for reminding me to add Unicode support so that the programs work properly with Stata 14.

                    Comment


                    • #11
                      Thanks for the update! Unfortunately, using the newest version (5.0) of your rundo and rundolines programs UltraEdit still does not work properly to with Stata 14.

                      I suggest to start a new topic about "Using external editors (e.g. UltraEdit) with Unicode support for Stata 14" (which I do, see http://www.statalist.org/forums/node/1300406).

                      Comment

                      Working...
                      X