Creating a new variable with if and or statement

Creating a new variable with if and or statement

by Emily Hurstak -
Number of replies: 1

Quick question on generate command: is there a way to generate newvar = 0, replace newvar=1 if othervar=1 OR diffvar=1

STATA doesn't like my "OR" syntax but I can't seem to figure out how to do this simple change with generate or egen.  Thanks for the help! 

In reply to Emily Hurstak

Re: Creating a new variable with if and or statement

by Michael Peters -

the syntax for or is |  

it can be found below the delete key on macs.  I am not sure where it is on a PC keyboard but it is a straight line going down.

In addition, make sure you use the double = sign or == 

 

such as gen new var=1 if oldvar==1 | otheroldvar ==2

 

MCP