Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: AW: RE: Conditional stack


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: RE: Conditional stack
Date   Thu, 30 Jul 2009 18:42:13 -0400

<>

" I don't know if there's a single command that does this, though."


There is one (apart from the -cond- solution)...


******
clear*

input  ID	str1 V1 V2x	V2y	
1	x	6	12	
2	x	7	13	
3	x	8	14	
4	y	9	15	
5	y	10	16	
6	y	11	17	
end

compress

gen Vnew=((V1=="x")*V2x /* 
 */ +(V1=="y")*V2y)
 
list, noobs  
******


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von PEREZ PEREZ
JORGE EDUARDO
Gesendet: Donnerstag, 30. Juli 2009 15:27
An: [email protected]
Betreff: st: RE: Conditional stack

gen vnew=.
replace vnew=v2x if v1=="x"
replace vnew=v2y if v1=="y"

I don't know if there's a single command that does this, though.
_________________________
Jorge Eduardo Pérez Pérez

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of HSIUTZU CHANG
Sent: jueves, 30 de julio de 2009 01:50 p.m.
To: [email protected]
Subject: st: Conditional stack

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/


*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index