Bookmark and Share

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]

st: How to normalize variables in stata


From   Xixi Lin <winnielxx@gmail.com>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   st: How to normalize variables in stata
Date   Thu, 25 Apr 2013 13:53:16 -0400

Hi,

I am trying to normalize variables, and the following is my code:
foreach x in x1 x2 x3{
gen N_`x' = .
gen mean_`x'=.
gen sd_`x'=.
}
forvalues i=2/120{
foreach x in x1 x2 x3{
qui sum `x' if Period==`i', meanonly
replace mean_`x'=r(mean) if Period==`i'
qui sum `x' if Period==`i', meanonly
replace sd_`x'=r(sd) if Period==`i'
}
}


forvalues i=2/120{
foreach x in x1 x2 x3{
replace N_`x'=(`x'-mean_`x')/sd_`x' if Period==`i'
}
}

however, the above code does not working, because it creates all
missing values for standard deviation. Can anyone help me to fix the
code? Thanks.

Best,
Xixi Lin
*
*   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/


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