how do I add values together in STATA?

how do I add values together in STATA?

by Ralph Wang -
Number of replies: 2

Hello:

I am trying to generate a variable (named the 'risk tolerance score") by adding up several values in a survey. I have tried generate RTS = var1+var2+var3, etc but I haven't figured it out. Is it an egen command? Does anyone have pointers for how to do this?

Ralph

 

In reply to Ralph Wang

Re: how do I add values together in STATA?

by Sofia Verstraete -

Ralph,

It sounds like your command is correct.  By entering 

generate RTS=var1+var2+var3

you should obtain a variable named RTS with the sum of all three.  There may however be issues with your data that could be complicating things.  First, make sure that your values in var1-var3 are numeric (they should appear in black font in the browser).  If they are a string variable STATA will not recognize them as a number to be added.  If they are red (a string variable) you will need to clean the data and destring prior to adding them up.  

Hope this helps! Let us know if it doesn't...

Sofia 

In reply to Ralph Wang

Re: how do I add values together in STATA?

by Sofia Verstraete -

Ralph,

It sounds like your command is correct.  By entering 

generate RTS=var1+var2+var3

you should obtain a variable named RTS with the sum of all three.  There may however be issues with your data that could be complicating things.  First, make sure that your values in var1-var3 are numeric (they should appear in black font in the browser).  If they are a string variable STATA will not recognize them as a number to be added.  If they are red (a string variable) you will need to clean the data and destring prior to adding them up.  

Hope this helps! Let us know if it doesn't...

Sofia