(scatter length_text week if group = 1, xlabel(0 (1) 10) `option3') /// (scatter length_video week if group = 2, xlabel(0 (1) 10) `option2') /// graph twoway (scatter length_video week if group = 1, xlabel(0 (1) 10) `option1') /// local option4 msymbol(th) mcolor(dknavy) clcolor(dknavy) connect(l) local option3 msymbol(o) mcolor(dknavy) clcolor(dknavy) connect(l) local option2 msymbol(th) mcolor(cranberry) clcolor(cranberry) connect(l) local option1 msymbol(o) mcolor(cranberry) clcolor(cranberry) connect(l) To use macros to hold multiple options to make a graph: local condition “if level = 1 & track != 2” local control `control' high_school entrance_exam admission_track In the case of holding long variable lists in a macro, we can extend the macro each time by referring to itself from the last iteration: reg gpa `application' `open_day' `placement' `control'
![stata if else stata if else](https://i.ebayimg.com/images/g/xG0AAOSwgXBgnOmF/s-l400.jpg)
local open_day writing interview participation We can then use the macros in the OLS regressions where application, open_day and placement have all the relevant independent variables and control has all the control variables. To change the contents of a macro, we simply redefine the contents where they are.įirst defines the local macro container and then modifies the contents of container simply by reassigning the variables.īelow we discuss some common scenarios where one can use macros to automate the analyses.īack to top The many uses of macros defining variable listsĪ common use of macros is to hold variable lists for later use.īelow we created a local macro control to hold all control variables, and macros application, open_day and placement to hold variable lists on application, open day performance and placement tests. Make sure you remember all the global macros you created elsewhere. We use a dollar sign to refer to a global macro: $ globalmacro.īe careful with the global macros that are accessible from all do-files and programs. Global macros work across the programs in Stata. Local reason `" "Work on a class assignment/paper" "Use specialized databases (e.g. However, if the strings contain spaces in between, we need to enclose `" "'. Usually we can define macros of strings with or without the quotation marks. Note that the left side is a backtick(`) usually found on the top left corner of the keyboard, and the right side is a apostrophe('). This is how you refer to a local macro: `localmacro'. Local macros only work in the current do-file or program. Macros are strings we assign to represent variables, values, texts, commands, statements etc. Gabriel Rossman, Introduction to Stata Programmingīack to top Macros Local and global macros *! Version 0.UCLA: Statistical Consulting Group, Introduction to Stata Programming Such a program might look like the following:
![stata if else stata if else](https://www.princeton.edu/~otorres/Stata/dofile_files/image045.jpg)
foreign and will execute it whenever autoreg is run as if it were an ordinary command.Īs a first extension, we might try writing a command that is not dependent on the data, such as one that would list all the values of each variable for us.
![stata if else stata if else](https://www.stata.com/why-use-stata/i/forest-graph.png)
For example, we might write the following program in an ordinary do-file: Using program drop before the block will ensure that the command space is available. When a program command block is executed, Stata stores (until the end of the session) the sequence of commands written inside the block and assigns them to the command name used in the program command. The program command defines the scope of a Stata program inside a do-file or ado-file. The tempvar, tempfile, and tempname commands all create objects that can be used within the scope of program execution to avoid any conflict with arbitrary data structures.The syntax command parses inputs into a program as macros that can be used within the scope of that program execution.
![stata if else stata if else](https://i1.wp.com/www.thedatahall.com/wp-content/uploads/2020/05/stata-dummy-variable-1.png)