try
gen Vnew=cond(V1=="x",V2x,cond(V1=="y",V2y,.))
hth,
Jeph
HSIUTZU CHANG wrote:
Dear Statalist users,
I want to generate a new variable
Vnew= V2, but using V2x or V2y will depend on the value of V1
Vnew =V2x if V1=x
Vnew =V2y if V1=y
ID V1 V2x V2y Vnew
1 x 6 12 6
2 x 7 13 7
3 x 8 14 8
4 y 9 15 15
5 y 10 16 16
6 y 11 17 17
What is the command I should use if I want the result of Vnew look
like the above table?
Thanks
Betty
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/