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: rescaling a variable by the maximum value question


From   "Justina Fischer" <[email protected]>
To   [email protected]
Subject   Re: st: rescaling a variable by the maximum value question
Date   Sat, 13 Oct 2012 10:02:35 +0200

you can generate a variable that takes on the maximum value

e.g.

 su age
gen var = `r(max)'

gen newvar = oldvar/var


see also return list after  the sum command

HTH

Justina




-------- Original-Nachricht --------
> Datum: Sat, 13 Oct 2012 01:49:07 -0400
> Von: "JVerkuilen (Gmail)" <[email protected]>
> An: [email protected]
> Betreff: st: rescaling a variable by the maximum value question

> I'm sure I'm simply overlooking something easy but I want to make a
> new variable that is rescaled by dividing by the maximum value of the
> old one. Old variable: 1, 2, 3, 4. New variable should be 0.25, 0.5,
> 0.75, 1.
> 
> The syntax
> 
>      gen newvar = oldvar/max(oldvar)
> 
> does not work and I understand why it doesn't, because max doesn't
> work that way. Is there a straightforward way to do this? (Yes I could
> simply
> 
>      summarize oldvar
> 
> and pick out the max by hand and rescale. I'd like to avoid that, if
> possible. ;)
> *
> *   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/
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index