Tag: local
-
Information about Stata macros: number of elements and order within locals and globals
Especially when running loops (see our posts here), it can be important to get more information about a macro, such as the length, or its first or last element.
-
Format how locals are displayed in Stata
Often I use locals to calculate something (such as the mean of a variable for a specific group) and use this in a loop (say, over groups or over years). If you, for example, want to calculate the share of observations that belong to one group (say: female==1), you could simply write
-
Add current date to Stata file names (and others)
We wrote earlier about how to add time stamps (current date and/or time) to your Stata figures, e.g. to keep track of work in progress results. A similar strategy can be used when storing log-files, which are typically overwritten with a more recent version of the same log.
-
Use of embedded quotation marks within locals in Stata
Proper use of single and double quotation marks is essential when working in Stata, especially when writing loops where locals can be a huge time and memory saver. The use of single and double quotation marks is rather straightforward (using ` and ‘ for single, and ” for double quotation marks). You can rather easily […]
-
Technical note: use of quotation marks
Be aware of the proper use of single and double quotation marks when copying Stata or other codes from this blog (but also when copying codes from other websites). Often opening or closing quotation marks are wrongly formatted.
-
Running regressions with similar sets of variables
Quite often we run variations on regressions, including or excluding (sets of) variables. Copy-pasting the regression and eliminating the variables to be excluded is one way, but given that we speak of sets of variables why not use locals to do the work for you:
-
Using Stata to randomise vignettes in NetQuestionnaire
One huge disadvantage of NetQuestionnaire (NetQ) is that randomisation is only possible for the order of sub-items of questions. There is, however, a way to use Stata to make anything random (e.g. the order of questions, content of questions). Below, I describe a way how to generate randomly sets of vignettes. At the end of […]
-
Why doesn’t this do-file run through …?
Quite often a do-file is written to run on various data-files that all seem to be the same. Say, you have done it for one year of a data-set and want to repeat the same for the subsequent years that you have data. Now, a check whether the data actually has some data (given your […]
-
Export single numbers to LaTeX or MS Word
In a text, you often you refer to a number (e.g. the number of observations in the estimation sample). There is a simple way to automise the export of this number from a Stata-do-file to a Latex-document.
-
Using locals and loops to generate longĀ strings
The following command can be used to generate a command which consists of several new variables which are generated within a loop. This could either be done by (e.g. generating a number of log variables) gen newvar1 = log(var1) gen newvar2 = log(var2) etc.