Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: standardizing on [0,1]


From   "Nick Winter" <nwinter@policystudies.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: standardizing on [0,1]
Date   Fri, 19 Jul 2002 12:55:10 -0400

You want to subtract the minimum of the variable, then divide by the
range:

	sum myvar
	replace myvar = (myvar - `r(min)') / (`r(max)'-`r(min)')

For lots of variables, this can be rolled up in foreach:

	foreach var in thisvar thatvar othervar {
		qui sum `var'
		replace `var' = (`var' - `r(min)') / (`r(max)'-`r(min)')

	}

Nick Winter

> -----Original Message-----
> From: Moliterno, Thomas [mailto:TMoliter@gsm.uci.edu] 
> Sent: Friday, July 19, 2002 12:49 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: standardizing on [0,1]
> 
> 
> I have a variable with values ranging from -1.58e-6 to 946515 (annual
> scores on a particular matrix derived measure).  I would like to
> standardize these values on [0,1] so that the observation with the
> highest value is given the value 1.  Any thoughts on an 
> efficient way to
> do this?  Thanks to all in advance.
> 
> Tom
> 
> **********************************************
> Thomas P. Moliterno
> Graduate School of Management
> University of California, Irvine
> tmoliter@uci.edu
> **********************************************
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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