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

Re: st: Automatic mean-centering?


From   [email protected]
To   [email protected]
Subject   Re: st: Automatic mean-centering?
Date   Wed, 25 Aug 2004 14:50:36 -0500

Clive,

How about this: 


*! Cribbed from Jeff Pitblado's -zval-
program clive_centered
	syntax varlist(min=1) [aw fw] [, PREfix(string) ]

	/* check options */
	if `"`prefix'"'!="" {
		confirm name `prefix'
	}
	else {
		local prefix "clive_"
	}

	if "`weight'"!="" {
		local weight [`weight'`exp']
	}
	foreach name of local varlist {
		capture confirm new variable `prefix'`name'
		if _rc {
			di as error "no action taken for `name':  " /*
			*/ "`prefix'`name' already exists"
		}
		else {
			qui summ `name' `weight'
			gen `prefix'`name' = (`name'-r(mean))
			label var `prefix'`name' "Demeaned `name'"
		}
	}
end
exit


The syntax would be -clive_centered price-trunk-


Hope this helps,
Scott

----- Original Message -----
From: Clive Nicholas <[email protected]>
Date: Wednesday, August 25, 2004 2:11 pm
Subject: st: Automatic mean-centering?

> All,
> 
> I'm interested in re-running old models by mean-centering all my
> continuous variables for comparison, as well as obtaining meaningful
> intercept values. At the same time, I wish to include dummy variables
> which, for obvious reasons, would not be mean-centered.
> 
> Now I know how to do this manually, as we all do:
> 
> . gen splodge = spludge-100
> 
> where 100 is the mean of SPLUDGE. But I'm interested to know if 
> there's a
> quicker way, especially if I have a _lot_ of continuous variables to
> mean-centre.
> 
> Having explored the help files for -xi- and Mitchell and Ender's -
> xi3-
> (which IS downloadable via SSC, unlike -renvars-!), neither routine
> automatically creates mean-centered variables. Searching -findit- 
> _and_the archive turned up nothing and nothing relevant respectively.
> 
> If anyone has any ideas, I'd be keen to hear them. Ta!
> 
> CLIVE NICHOLAS        |t: 0(044)191 222 5969
> Politics              |e: [email protected]
> Newcastle University  |http://www.ncl.ac.uk/geps
> *
> *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index