**Introduction**

For a normally distributed variable, a z score assigns a number to each data point based on its distance, in standard deviations, from the mean. For example, if the mean of variable iq is 100, with sd 15, then an iq of 100 has a z score of 0, an iq of 85 has a z score of -1, and an iq of 115 has a z score of 1. In this blog, we’ll show you how to use Stata code to create z scores for each value in a normal distribution.

**Generate Normally Distributed Data**

First, let’s generate a normally distributed variable, iq, with 1,000 observations, a mean of 100, and a standard deviation of 15.

set obs 1000

drawnorm iq2, mean(100) sd(15)

gen iq = round(iq2)

drop iq2

label variable iq "IQ"

summarize iq

return list

We are very close to the desired mean of 100 and the desired standard deviation of 15.

Stata has captured the scalars for you:

**Create z Scores**

Now try the following code:

gen z = (iq-r(mean))/r(sd)

list in 1/30

The code above took every value, subtracted the mean from it, and divided it by the standard deviation, leading to the z scores we see here.

BridgeText can help you with all of your **statistical analysis needs**.