- #StataTip: for blockwise selection of code in @Stata|’s do-file editor, press the option key (Mac) or alt key (Windows) and mark the respective cells with your mouse/cursor.
- #StataTip: to format output in your log file or results window in @Stata, you can print text in red (–di as error “Text in red”–) or bold (–di as result “Text”–). If you are using black background use “as text” (green), “result” (yellow), “error” (red), and “input” (white)
- #StataTip: to list all globals and locals that are currently active, write –macro list– @Stata
- #StataTip: display a variable’s label by writing –`”`: var label VARNAME’”‘– (watch out for the right quotation marks!). This can be useful, e.g. for labelling @Stata figures
- #StataTip: to break the execution of a @Stata loop (eg when certain conditions are met), add –continue– and Stata will move to the next iteration (to stop the loop entirely, write –continue, break–)
- #StataTip: if you want to use quotation marks in a local, embed the local in compound quotation marks:
- #StataTip: variable lists selected by “*” select all variables. To select all but a few (e.g. “year”) write –ds year, not– and get all variables but the one specified (results stored in local `r(varlist)’)
- #StataTip: use missing(VAR)==1 to condition on variable VAR being missing
- #StataTip: use –set varabbrev off– to only allow full variable names in your Stata code (and no abbreviations)
- #StataTip: use inlist(VAR,a,b,c,…,y)==1 to condition on numerical a, b, c, etc. Works also for string variables!
- #Statatip: use inrange(VAR,MIN,MAX)==1 to condition on MIN<=VAR<=MAX
- #Statatip: always define your Stata version in your do-file with e.g. “version 17” – this can be crucial for replicating results later
- #StataTip: use –which name_ado_file– to show from which folder Stata calls the .ado-file