Announcement

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

  • Saving do file from a script

    I would like to save the do file automatically each time I run it completely.
    I have read this post and if I save the do file with the following script

    Code:
    save mydofile.do
    when I open this file there is just gibberish in it--as discussed in the linked post.

    Then, I found this Stata manual chapter, with further explanation in here.
    Based on that information, this is how I write my do file:

    Code:
    cap cmdlog close
    cap log close      
            
    local today: di %td_N-D-CY date(c(current_date),"DMY")
    cmdlog using "mypath\myfolder\Cleaning and analyses`today'.txt", replace
    log using "mypath\myfolder\Cleaning and analyses`today'", replace
    
    <my commands to Stata>
    
    cap log close
    cap cmdlog close
    Based on this script, I expect to find in "myfolder" a smcl file--generated with the log command--and a txt file--generated with the cmdlog command.
    I correctly find both files.
    However, the smcl reports anything as expected (i.e. both inputted commands and output), while the txt file is empty (i.e. 0kb)
    When, I open this txt file is completely blank, while I would expect to find in there the commands I have inputted.

    What is wrong with what I am doing?
    Thanks in advance

    I am using Stata\SE 14.2, Windows 10 Home
    Last edited by FLuca; 25 Jan 2023, 03:58.

  • #2
    I assume you have a .do file and you want Stata to save that .do file whenever you execute it. Making logs is irrelevant for that particular problem. Instead you have to change your settings once, and Stata will do what you want forever (or at least until you have to reinstall Stata because you moved to a new laptop).

    So open a .do file, and go to Preferences:

    Click image for larger version

Name:	settings1.png
Views:	1
Size:	18.5 KB
ID:	1698707


    Than, within the preference menu tick Always save before do/run

    Click image for larger version

Name:	settings2.png
Views:	1
Size:	18.3 KB
ID:	1698708
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      great, this will do it!
      I had heard about it, but did not have these precise directions, so I was looking into Stata's main window preferences
      Many thanks Marteen!

      As a side note, for curiosity sake, I am still wondering why the cmdlog was not doing what is supposed to do.

      Comment

      Working...
      X