Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
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/