hasemera.blogg.se

If else stata
If else stata






if else stata

Using macros will give us a clear structure in model specifications. If the function msofhours() did not come to your mind.

if else stata

Macros can store values, especially constants, to be used in. Legend (order(1 "Average User: Video" 2 "Heavy User: Video" 3 "Average User: Text" 4 "Heavy User: Text")) (scatter length_text week if group = 2, xlabel(0 (1) 10) `option4'), /// (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' 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.

if else 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 UCLA: Statistical Consulting Group, Introduction to Stata Programming








If else stata