UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata FAQ
How do I standardize variables in Stata?

Consider the file we call smauto that contains four variables, make, mpg, weight, and price.
use http://www.ats.ucla.edu/stat/stata/faq/smauto, clear

list 

     +------------------------------------------------+
     |          make        mpg     weight      price |
     |------------------------------------------------|
  1. |   AMC Concord         22       2930       4099 |
  2. |     AMC Pacer         17       3350       4749 |
  3. |    AMC Spirit         22       2640       3799 |
  4. | Buick Century         20       3250       4816 |
  5. | Buick Electra         15       4080       7827 |
     +------------------------------------------------+
You can use the egen command to make standardized variables.  The commands below make standardized values for mpg and weight (called zmpg and zweight).
egen zmpg = std(mpg)
egen zweight = std(weight)
You can confirm that the variables were standardized properly with the summarize command.
summarize
The results below show that indeed zmpg and zweight are standardized (the mean is very close to, but not exactly 0 due to slight rounding error).
    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
        make |         0
         mpg |         5        19.2    3.114482         15         22
      weight |         5        3250    541.6179       2640       4080
       price |         5        5058    1606.718       3799       7827
        zmpg |         5   -1.79e-08           1  -1.348539   .8990258
     zweight |         5   -2.98e-09           1  -1.126255   1.532446

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California