Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: RE: RE: Copying the contents of existing variables into a new variable


From   Ronnie Babigumira <[email protected]>
To   [email protected]
Subject   Re: st: RE: RE: Copying the contents of existing variables into a new variable
Date   Thu, 24 May 2012 23:42:24 +0200

This may be useful http://blog.stata.com/2012/04/02/the-penultimate-guide-to-precision/


-- 
010100100110111101101110011011100110100101100101




On Thursday, May 24, 2012 at 10:31 PM, Lucie Vlach wrote:

> Hello again!
> Thank you Nick and Ronnie!
> egen newvar = rowmax(var1 var2) (from Ronnie) and your confirmation of my command is very helpful!
> 
> But for some reason the var1 values are changed once they end up in var3. Var1 changes from the actual value of 699659108 (correct one) to 699659136. But the var2 (value of 571000128) stays correct in var 3.
> 
> Var1 and var2 come from 2 appended 2 datasets (var 1 from dataset1 and var2 from dataset2), but I made sure that both variables are recasted as double before I try the var3 creation command.
> 
> I also tested this all on someone else's computer using their Stata, just to make sure my Stata is working fine. The same problem happened there, too.
> 
> Do I need the vars to be in certain format before I create var3?
> 
> Thank you!
> 
> Lucie
> 
> ________________________________________
> From: [email protected] (mailto:[email protected]) [[email protected] (mailto:[email protected])] On Behalf Of Nick Cox [[email protected] (mailto:[email protected])]
> Sent: May 24, 2012 12:43 PM
> To: '[email protected] (mailto:[email protected])'
> Subject: st: RE: Copying the contents of existing variables into a new variable
> 
> The -generate- command you give is fine.
> 
> . clear
> 
> . input var1 var2
> 
> var1 var2
> 1. 345 .
> 2. 345 .
> 3. 345 .
> 4. 345 .
> 5. . 678
> 6. . 678
> 7. . 678
> 8. . 678
> 9. end
> 
> . gen newvar = max(var1, var2) if missing(var1, var2)
> 
> . l
> 
> +----------------------+
> | var1 var2 newvar |
> |----------------------|
> 1. | 345 . 345 |
> 2. | 345 . 345 |
> 3. | 345 . 345 |
> 4. | 345 . 345 |
> 5. | . 678 678 |
> |----------------------|
> 6. | . 678 678 |
> 7. | . 678 678 |
> 8. | . 678 678 |
> +----------------------+
> 
> It should not change the value of -var1-. If that happens, your copy of Stata is corrupted.
> 
> Nick
> [email protected] (mailto:[email protected])
> 
> Lucie Vlach
> 
> I need to create a new variable that will copy data from other variables (2 or more) and combine them into the new one. The existing vars will only have a number or missing value.
> I found something similar on this list, and I tried:
> 
> gen newvar = max(var1, var2) if missing(var1, var2)
> 
> But it's changing the value of var1.
> I would like to see the newvar look like this:
> 
> SAMPLE DATA:
> var1 var 2 newvar
> 345 . 345
> 345 . 345
> 345 . 345
> 345 . 345
> . 678 678
> . 678 678
> . 678 678
> . 678 678
> ETC
> (I use Stata/IC 11.2)
> 
> 
> *
> * 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/
> 
> This message and any attached documents are only for the use of the intended recipient(s), are confidential and may contain privileged information. Any unauthorized review, use, retransmission, or other disclosure is strictly prohibited. If you have received this message in error, please notify the sender immediately, and then delete the original message. Thank you.
> 
> *
> * 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index