#StataTip

2025-05-11

#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.

2025-04-13

#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.

2025-03-26

#StataTip: use inlist(VAR,a,b,c,...,y)==1 to condition on numerical a, b, c, etc. Works also for string variables!

2025-03-19

#StataTip: to suspend 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--)

2025-03-06

#StataTip: use missing(VAR)==1 to condition on variable VAR being missing

2025-02-10

#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)') – thank you #NickCox!

2025-01-30

#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

2025-01-28

#Statatip: always define your #Stata version in your do-file with e.g. "version 17" - this can be crucial for replicating results later

2025-01-13

#StataTip: use missing(VAR)==1 to condition on variable VAR being missing

2025-01-02

#StataTip: use --set varabbrev off-- to only allow full variable names in your #Stata code (and no abbreviations)

2024-12-31

#Statatip: use inrange(VAR,MIN,MAX)==1 to condition on MIN<=VAR<=MAX

2024-12-24

#StataTip: if you want to use quotation marks in a local, embed the local in compound quotation marks:
local compound=`"Bernie said "Hi" "'|#StataTip: if you want to use quotation marks in a local, embed the local in compound quotation marks:
local compound=`"Bernie said "Hi" "'

2024-12-18

#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

2024-11-11

#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)

2024-11-07

#StataTip: use --set varabbrev off-- to only allow full variable names in your #Stata code (and no abbreviations)

2024-11-04

#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)

Asjad Naqvi :stata:asjadnaqvi@econtwitter.net
2023-04-16

A very pro #StataTip:

You can split & stack your dofiles in tabbed windows. Just drag a dofile to the left of the dofile editor and click "New vertical tab group"

This is highly useful for parallel updating or comparing multiple files, and makes the workflow easier.

Asjad Naqvi :stata:asjadnaqvi@econtwitter.net
2023-02-19

A pro #StataTip for #reshape that I just rediscovered while fixing some code on the train:

One can use the @ in reshape commands to indicate where the j-index is. This is especially useful if:
(a) variable names r not consistent (fig 👇)
(b) variable names have mutiple numbers

Asjad Naqvi :stata:asjadnaqvi@econtwitter.net
2023-01-28

A #StataTip: If you are repeatedly using the same set of commands, for example for graphs or regressions, then:

1) start using macros, and/or
2) define small programs

This saves you:
(a) space, and
(b) the hassle of copy/pasting

and looks neater!

Asjad Naqvi :stata:asjadnaqvi@econtwitter.net
2023-01-27

A #Statatip that I rediscovered while updating this article: you can change whether your graphs are tabbed or not. Graphs popping up in separate windows makes life so much easier when comparing stuff:

All you need to do is "set autotabgraphs off"

---
RT @asjadnaqvi
A #Statatip: If you r making multiple graphs & want to keep them on the screen, name them. This will ensure that they all stay open. Without names, the newer replaces the o…
twitter.com/AsjadNaqvi/status/

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst