Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: New variable based on two other variable


From   daniel klein <klein.daniel.81@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: New variable based on two other variable
Date   Sat, 6 Apr 2013 11:04:54 +0200

David,

my approach would be a one-step using the -max()- function

g right = max(govshr, prishr) if !mi(govshr, prishr)

As already incidacted by the -if- condition, you need to think about
what to do with missing values in one or both the variables (I set all
those cases to missing). You also need to think about ties.

Best
Daniel

--

Hi,

I want to generate a variable based on two existing variables.

I have two variables : govshr and prishr and the variable I need is to
take the value of govshr or prish whichever is greater.
I tried the following but the result is not what I want
1. gen right=0
2. replace right=govshr if govshr>prishr
3. replace right=prishr if prishr>govshr
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index