I have the following data structure (variables):
a aa b bb c cc d dd
I define two macros:
global macro1 a b c d
global macro2 aa bb cc dd
I can easily generate the sum of certain variables using the command:
egen var=rowtotal($macro1)
How can I apply -if- conditions using the command above and the macro2 in the sense that
egen var=rowtotal($macro1) if $macro2==1
i.e. if aa==1 or bb==1 or cc==1 or dd==1
i.e. take the rowsum of every variable in $macro1 if the corresponding variable in $macro2 equals 1 (take the sum of a if aa==1 and b if bb==1 etc).
Thanks for your help.
a aa b bb c cc d dd
I define two macros:
global macro1 a b c d
global macro2 aa bb cc dd
I can easily generate the sum of certain variables using the command:
egen var=rowtotal($macro1)
How can I apply -if- conditions using the command above and the macro2 in the sense that
egen var=rowtotal($macro1) if $macro2==1
i.e. if aa==1 or bb==1 or cc==1 or dd==1
i.e. take the rowsum of every variable in $macro1 if the corresponding variable in $macro2 equals 1 (take the sum of a if aa==1 and b if bb==1 etc).
Thanks for your help.
Comment