Hi Friend,

I have a dataset with 40 variables. I need to create a new variable which added a suffix "comment" from the exiting variables and assigned value according to two variables.


I do not want to writ the code like this for the 40 variables. How can I write the code such as a do loop in stata?

Code:
 gen carry_comment = "wrong"
if (carry == 0 & carryhr ~= 0 & carryhr ~= .) | (carry == 1 & (carryhr == 0 | carryhr ==.))
data have:
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str18 ssid byte carry double carryhr str5 
"15SWHB-LND-245-MVR" 1 0 
end
------------------ copy up to and including the previous line ------------------


data I want for one of the variable:

----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str18 ssid byte carry double carryhr str5 carry_comment
"15SWHB-LND-245-MVR" 1 0 "wrong"
end
------------------ copy up to and including the previous line ------------------


Many thanks.