*! version 2.1.2 22may2020

cdo

cdo -- Alternative to Stata's do: get an update when the dofile stalls and other quality of life improvements

Syntax

cdo filename
[, arguments(string)
options]

Main
arguments(string) any arguments you want to pass on to your dofile

url(string) sendtoslack url or saved name to get updates (on success/failure)

program(string) program you want to run on program end (...)

log(log_opts) make a log (some extra features described below)

nocopy do not make a local copy of the dofile

run run dofile instead of do-ing it

saveoptions saves specified options as default (so you can omit them)

Description

cdo is just like Stata's default do but then with some extra features.

1. Executes a local copy of the dofile instead of the original file

-> You can still edit the dofile while it is running (no sharing violation errors)

-> Your program won't halt when the connection between your computer and the dofile is broken (e.g. you unplugged external drive or server lost connection)

2. Can send an update on errors/completion to your smartphone with the url() option

3. Can execute a program upon errors/completion

-> E.g. log out of pay-per-minute server

4. Create log files internally

-> Functionality built in to add time/date to name of logfile

The main inspiration for this command was frustration. Often I'd start a long dofile and move on, only for it to crash after 5 lines because of some stupid coding mistake.
Likewise, I've lost many computer-hours due to network issues
causing the server to lose access to the dofile and just stopping dead in its tracks.
This, and many other problems can be fixed by using this command.

Finally, to cater to my own laziness, cdo has a saveoptions feature, which places any options you specified in the profile.do file.
The command will then use these options the next time you use cdo, without requiring you to add the options (overwrite by typing "overwrite" or "no", see examples). It's quite cool, even though I say so myself.

Options

arguments(string) Known by few, it is possible to pass arguments to your dofile. For more info, see the manual section.

url(string) If you specify a valid sendtoslack url or name in url(), cdo will send a message to the specified Slack room (-> your smartphone) to inform you
upon errors or completion. If you want to send to the default you saved in sendtoslack, specify url(default). See sendtoslack for more information.

program(string) You can tell cdo to execute a certain program on errors/completion.
This program will also be able to access the return code (error) that the dofile produced,
which allows you to distinguish your response based on successful or failed execution.
See the worked example for more info.

log(log_opts) The log() syntax is as follows: log(filename [, append replace text smcl date time forcemsg]).
filename is where you want to save the log.
append/replace/text/smcl are standard log options.
date and time will respectively add the current date and time to the logfile's document name.
forcemsg tells cdo to display the msg you get when you close a log (by default it is omitted).

saveoptions Some of these options you might want to use all the time (e.g. you generally only use one url for the smartphone updates).
If you execute cdo with saveoptions, it will save any specified options to profile.do.
Any subsequent use of cdo will then use these options. In exceptions, you can specify that option with an "overwrite" or "no" argument.
That will not work for argument-free options. In that case you will have to clear the global yourself (e.g. global cdo_run "").
The examples might clarify this a bit.

Examples

Execute the copy of a dofile
. cdo "C:/StataWD/sleep 2000.do"

Run the copy instead
. cdo "C:/StataWD/sleep 2000.do", run

Save a text log called thelog.
. cdo "C:/StataWD/sleep 2000.do", log(C:/StataWD/thelog, replace text)

Save a text log and call it thelog_28Nov2018_165504 (at time of writing)
. cdo "C:/StataWD/sleep 2000.do", log(C:/StataWD/thelog, replace text date time)

Execute a dofile (don't copy it first)
. cdo "C:/StataWD/sleep 2000.do", nocopy

Send a message to webhooks channel upon completion/error
. cdo "C:/StataWD/sleep 2000.do", url(https://hooks.slack.com/services/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)

Perform program upon completion/error

program define helloWorld

. di "Hello World"

. if `s(returnCode)' == 0 di "Success!"

. if `s(returnCode)' != 0 di "Failure!"

end

. cdo "C:/StataWD/sleep 2000.do", program(helloWorld)

Save url option

. cdo "C:/StataWD/sleep 2000.do", saveoptions url(https://hooks.slack.com/services/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)

Use saved option

. cdo "C:/StataWD/sleep 2000.do"

Save run option

. cdo "C:/StataWD/sleep 2000.do", saveoptions run

Use saved run option, but not the saved url

. cdo "C:/StataWD/sleep 2000.do", url(no)

Do not use saved options

. global cdo_run ""

. cdo "C:/StataWD/sleep 2000.do", url(no)

. cdo "C:/StataWD/sleep 2000.do", url(overwrite)

Author

Jesse Wursten
Faculty of Economics and Business
KU Leuven
jesse (dot) wursten (at) kuleuven (dot) be}

Other commands by the same author

sendtoslack Stata Module to send notifications from Stata to your smartphone through Slack

stop Stata command to interrupt dofiles intelligently (closes logfiles and optionally sends a message to your smartphone)

xtqptest Bias-corrected LM-based test for panel serial correlation

xthrtest Heteroskedasticity-robust HR-test for first order panel serial correlation

xtistest Portmanteau test for panel serial correlation

xtcdf CD-test for cross-sectional dependence

timeit Easy to use single line version of timer on/off, supports incremental timing

pwcorrf Faster version of pwcorr, with builtin reshape option