Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: rescaling a variable by the maximum value question |

Date |
Sat, 13 Oct 2012 10:23:40 +0100 |

Justina is correct. You can create a new variable, but there is no need to do that. su age, meanonly gen age2 = age / r(max) -su, meanonly- is more efficient when you just want a maximum. (The name -meanonly- is not indicative here.) That's unimportant in one-off cases, but a detail to note if doing this repeatedly. SJ-7-3 st0135 . . . . . . . . . . . Stata tip 50: Efficient use of summarize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox Q3/07 SJ 7(3):438--439 (no commands) tip on using the meanonly option of summarize to more quickly determine the mean and other statistics of a large dataset What Jay is missing is that -max()- will in his context not return a scalar that is the maximum of a variable. In fact Stata functions typically do not that, return a scalar that summarizes a variable. -max()- wants two or more arguments and will return the result of comparing them, as it were rowwise. If -max(x, y)- were calculated from two variables -x- and -y-, then there is scope for a new variable to be produced. Nick On Sat, Oct 13, 2012 at 9:02 AM, Justina Fischer <JAVFischer@gmx.de> wrote: > 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 "JVerkuilen (Gmail)" <jvverkuilen@gmail.com> >> 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/

**Follow-Ups**:**Re: st: rescaling a variable by the maximum value question***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**st: rescaling a variable by the maximum value question***From:*"JVerkuilen (Gmail)" <jvverkuilen@gmail.com>

**Re: st: rescaling a variable by the maximum value question***From:*"Justina Fischer" <JAVFischer@gmx.de>

- Prev by Date:
**Re: st: RE: How do I properly tell Stata this data is Panel Data?** - Next by Date:
**st: Heteroscedasticity for Tobit** - Previous by thread:
**Re: st: rescaling a variable by the maximum value question** - Next by thread:
**Re: st: rescaling a variable by the maximum value question** - Index(es):