How do I create an indicator variable which refers to multiple variables? All the relevant variables have the same words at the beginning of their names – for example “ev_mon_” in this example data file
The new indicator variable will be 1 where the month observation is equal to the date in the “ev_mon_” variables but 0 if after 6 months following the “ev_mon_” date (and zero if before that date). The thing I am having difficulty with is for the expression to apply relational operators across the full sequence of “ev-mon_” variables (ie ev_mon_1, ev_mon_2, ev_mon_3 etc out to 120 variables).
I get the command for referring to one of the “ev_mon” variables, eg
But I don’t yet see the appropriate way to refer to multiple variables, eg (for a failed attempt)
I hope that makes sense? I am using Stata 15. Thank you for your help, Dan
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long id float(month ff ev_mon_1 ev_mon_2) 2708 657 -.005559 658 670 2708 658 -.0023612394 658 670 2708 659 .0009129993 658 670 2708 660 -.0016764477 658 670 2708 661 -.0025546604 658 670 end format %tmCCYY_Mon month format %tmCCYY_Mon ev_mon_1 format %tmCCYY_Mon ev_mon_2
I get the command for referring to one of the “ev_mon” variables, eg
Code:
gen byte new_var=0 replace new_var = (month>ev_mon_1 & month<(ev_mon_1+7))
Code:
gen byte exog2 = (month>ev_mon_* & month<(ev_mon_*+7))
Comment