{smcl} {* 13apr2017}{...} {hline} help for {hi:center} {hline} {title:Center (or, optionally, standardize) variables} {p 8 15 2} {cmd:center} {it:varlist} [{it:weight}] [{cmd:if} {it:exp}] [{cmd:in} {it:range}] [, {cmdab:c:asewise} {cmdab:i:nplace} {bind:{ {cmdab:pre:fix(}{it:prefix}{cmd:)} | {cmdab:g:enerate(}{it:newvar}{cmd:)} }} {cmdab:th:eta:(}{it:#}|{it:varname}{cmd:)} {cmdab:s:tandardize} {cmdab:r:eplace} {cmdab:d:ouble} {cmdab:nol:abel} {cmdab:a:ddtolabel(}{it:string}{cmd:)} {cmdab:mean:save}[{cmd:(}{it:prefix}|{it:newvar}{cmd:)}] {cmdab:sd:save}[{cmd:(}{it:prefix}|{it:newvar}{cmd:)}] ] {p 4 4 2} {cmd:by} {it:...} {cmd::} may be used with {cmd:center}; see help {help by}. {p 4 4 2} {cmd:aweight}s, {cmd:pweight}s, {cmd:iweight}s, and {cmd:fweight}s are allowed; see help {help weights}. {title:Description} {p 4 4 2} {cmd:center} centers (or, optionally, standardizes) the variables in {it:varlist}. For each {it:varname} in {it:varlist}, a new variable {cmd:c_}{it:varname} is created containing the centered (or standardized) values of that variable. {p 4 4 2} Use the {help by} prefix to center/standardize group-wise. {p 4 4 2} Technical note about the computation of standard deviations in the presence of weights: For {cmd:iweight}s and {cmd:fweight}s, the standard deviations are computed as sd(x) = sqrt( sum(w_i*(x_i - mu)^2) / (W - 1) ) {p 4 4 2} where mu = sum(w_i*x_i)/W is the mean of x and W = sum(w_i) is the sum of weights. For {cmd:aweight}s and {cmd:pweight}s, the standard deviations are computed as sd(x) = sqrt( sum(w_i*(x_i - mu)^2) / (W - W/N) ) {p 4 4 2} where N is the sample size. These rules are in line with how official Stata's {bf:{help summarize}} handles weights. {title:Options} {p 4 8 2} {cmd:addtolabel(}{it:string}{cmd:)} may be used to specify text which is to be added to the end of the labels of the new variables. The default is {bind:" (centered)"} or {bind:" (standardized)"}, depending on whether the {cmd:standardize} option is specified. Type {cmd:addlabel("")} to omit the suffix. {p 4 8 2} {cmd:casewise} specifies that cases with missing values be excluded listwise, i.e., that the centering/standardization be based on the sample that is not missing for any of the variables in {it:varlist}. The default is to use all the nonmissing values for each variable. {p 4 8 2} {cmd:double} enforces storage type {cmd:double} for newly created variables. {p 4 8 2} {cmd:generate(}{it:newvar}{cmd:)} specifies the name of the new variable to be created. Note that {cmd:center} may only be applied to one variable at a time if {cmd:generate()} is specified. {p 4 8 2} {cmd:inplace} causes the variables to be centered in place. That is, the centered values will replace the original values without creating new variables. {p 4 8 2} {cmd:meansave}[{cmd:(}{it:prefix}{cmd:)}] saves variables containing the means. The new variables will be named {it:prefix}{it:varname}. The default {it:prefix} is {cmd:m_}. Note that the saved means will not be affected by {cmd:theta()}. If {cmd:generate()} is specified, {cmd:meansave(}{it:newvar}{cmd:)} saves the mean(s) in {it:newvar}. {p 4 8 2} {cmd:nolabel} suppresses the assignment of labels to the new variables. The default is to use the label (or name) of the original variable with some text added to the end of it (see {cmd:addtolabel}). {p 4 8 2} {cmd:prefix(}{it:prefix}{cmd:)} allows the user to supply a prefix for the centered/standardized variables. The default prefix is {cmd:c_}, thus the new variables will be named {cmd:c_}{it:varname}. {cmd:prefix()} is not allowed if {cmd:generate()} is specified. {p 4 8 2} {cmd:replace} permits {cmd:center} to overwrite existing variables. {p 4 8 2} {cmd:sdsave}[{cmd:(}{it:prefix}{cmd:)}] saves variables containing the standard deviations (allowed only if the {cmd:standardize} option is specified). The new variables will be named {it:prefix}{it:varname}. The default {it:prefix} is {cmd:sd_}. If {cmd:generate()} is specified, {cmd:sdsave(}{it:newvar}{cmd:)} saves the standard deviation(s) in {it:newvar}. {p 4 8 2} {cmd:standardize} creates a variable containing the standardized values (zero sample mean and unit sample variance). Default is to create a variable containing the centered values (zero sample mean). {p 4 8 2} {cmd:theta(}{it:#}|{it:varname}{cmd:)} may be used for quasi-demeaning. Before subtraction, the means will be scaled by {it:#} or by the values of {it:varname} respectively. This is sometimes used in the context of panel data models (see Wooldridge, 2002:287, and the Methods and Formulas Section in {hi:[XT] xtreg}). {title:Examples} {inp}. sysuse auto . center mpg price weight . center mpg price weight, prefix(z_) standardize . bysort rep78: center mpg price weight, replace . center mpg, generate(mpg0) {txt} {title:References} {p 4 8 2} Wooldridge, J.M. 2002. Econometric Analysis of Cross Section and Panel Data. Cambridge (Mass.): The MIT Press. {title:Author} {p 4 4 2} Ben Jann, Institute of Sociology, University of Bern, ben.jann@soz.unibe.ch {p 4 4 2}I am grateful to Mark Schaffer, who provided the motivation for the {cmd:theta} option. {p 4 4 2} Thanks for citing this software as follows: {p 8 8 2} Jann, B. (2004). center: Stata module to center (or standardize) variables. Available from {browse "http://ideas.repec.org/c/boc/bocode/s444102.html"}. {title:Also see} {p 4 13 2} Manual: {hi:[R] summarize} {p 4 13 2} On-line: help for {help summarize}