
- #Referencing a file in stata located on a usb for mac how to#
- #Referencing a file in stata located on a usb for mac code#
I suggest you create a do-file template for tables and graphs (see my previous article on creating do-file templates). It would sure be easier to use a one word macro to represent all of the above. Ms(O) mc(gs0) msize(small)) (line populatn_hat d, sort lcolor(gs0)) (line populatn_hat_p d, sort lcolor(gs0) lpattern(dash)) (line populatn_hat_m d, sort lcolor(gs0) lpattern(dash)), xline(0, lcolor(gs0)) title(“Quadratic fit”, color(gs0)) ytitle(“Population in district”) legend(label(1 “Vote shares”) label(2 “Quadratic fit”)) This is an example of the coding for a graph that I once created: What are options for a graph? To name just a few, the major and minor tick labels for the X and Y axis, the X and Y axis scale properties, whether to have a legend, placement of the legend, placement of the title, etc. Unless you are Raymond (of Rain Man fame), there is no way you will remember your favorite options when creating a graph.

Que facil! Macros for formatting tables and graphsĪnother great use for macros is for creating tables and graphs.
#Referencing a file in stata located on a usb for mac code#
If you did use a macro you will only have to go back to the line of code for the macro and remove the variable from the group. If you didn’t use a macro you will have to go back to every line of code and remove it.

After reviewing your results you might decide to eliminate one of the variables. But wait, there is more.įor example, you might have to run numerous linear regressions, using several of the same predictor variables in each regression you run. Using a macro to represent several variables may not seem like a big deal and why bother with it. Note that each time you use the word continuous in a command line you must begin with the forward slanting single quote key ` (to the left of the 1 key on your keyboard) and finish with the backward slanting single quote key ‘ (to the right of the key on your keyboard). I then substitute the word continuous for the variable names in the the last lines. The command local tells Stata to use the word continuous to represent the variables educat, exper, wage, and age. The code below will perform the exact same actions as the code above.

Using a macro allows me to simplify my work, which will reduce the potential for errors and keep it organized. In the first line of my code above, local continuous educat exper wage age, I am using the word “continuous” to represent the four variables educat, exper, wage, and age. If you remember from the previous article, the wages data set had four continuous variables. If you will be analyzing more than one data set then you might want to consider using the local command. If you plan on analyzing only one data set then the global command shouldn’t cause you any problems. The command local tells Stata to keep everything in the command line in memory only until the program or do-file ends. If you open another data set before exiting, the global macro will still be in memory. The command global tells Stata to store everything in the command line in its memory until you exit Stata.
#Referencing a file in stata located on a usb for mac how to#
How to write a simple macro in StataĪ macro in Stata begins with the word “global” or “local”. Writing macros in Excel can be long and involved. Please note that a macro in Stata is not the same as a macro in Microsoft Excel. In Stata this process is known as a macro. Stata allows you to use a single word, such as “continuous”, to represent many other words. Let’s look at the first line from above: local continuous educatexper wage age Let me explain how simple it is to understand.

I admit it looks like a foreign language.
