I am trying to create a macro in Stata that will set a variable name for me to reference later on in my do
file. Essentially, I am trying to replace a variable name with a local macro.
An example dataset is the following:
ID Indicator1 Indicator2 Amount
1 1 0 10
2 0 1 2
3 0 0 3
4 1 0 5
5 1 1 20
My data has a number of indicators but I only have to work with only one indicator at a time. I want to put the indicator that I'm currently working with into a macro, so that I have to change only one thing in my entire code.
My code is:
local myvar = "Indicator"
What I want is to be able to use something like this:
sum Amount if "`myvar'" == 1
However, I keep getting an error that says "type mismatch"
even though myvar
has been defined.