/***************************************************************************** demean.ado Written by Russell Dimond 10/2002 for Programming in Stata This program will demean any number of variables, though it doesn't handle fancy variable lists (price-rep78, x*, etc.). If the users requests that it demean a string, it will give an error message but continue to process the other variables in the list. *****************************************************************************/ program define demean foreach var of local 0 { capture confirm numeric variable `var' if _rc==0 { quietly sum `var' replace `var'=`var'-r(mean) } else di "`var' is not a numeric variable and cannot be demeaned." } end