# Quantitative Techniques:

```Quantitative Techniques:
Laboratory 2
Excel: Creating a normal distribution from the Uniform
distribution and writing your first macro
Repeat the following instructions from lab 1 or re-open the file you created last week.
Producing a histogram
This will demonstrate the use of the random number generator, and frequency distribution
function.
1. Create a new spreadsheet and save with a name such as First histogram.
2. In Cell A1 type “=RAND()” (without the quotes)
3. Then copy this formula down as far as A1000.
4. Now copy it on to itself using Copy, Paste Special, Value
5. Now create a set of bins to put a frequency distribution in cells C2 to C12 as follows
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Now use Tools, Data analysis, histogram to produce a frequency table with A1 to A1000 as
the data and C2 to C12 as the bins or interval limits. (Hint; check the Chart Output box to
get a pictorial representation.)
What do you expect the frequencies to be ?
If you did not ask for chart output, generate a histogram from the frequencies using Excel’s
graphing capabilities. Insert suitable titles at the top and on each axis.
Is the shape of the histogram roughly as you would expect?
When you have done that, copy the 1,000 random numbers into the second sheet of the spreadsheet
starting at cell A2
In A1 insert the heading “uniform”. In B1 insert the heading “normal”.
In B2 type the function =norminv(A2, 0,1)1.
1
Norminv stand for the inverse function of the cumulative normal distribution. The second and third
parameters are the mean and standard deviation of the distribution. When you have the time, see if you
can figure out how this turns a uniform distribution into a normal one.
1
Copy this formula down to B1001. Tidy up the appearance by formatting the Cells A2:B1001as
Number…4 decimal places.
In C2 and below create the bins –2.6, -2.2, -1.8,
+2.2, +2.6.
Run Tools, Data Analysis, Histogram using these bins as output and column B as input and check the
(probably bottom) box in the histogram dialog box which specifies a chart output .
Now repeat this and tick the box marked cumulative distribution.
Success? Congratulations! You have created and graphed a standard normal distribution!
In A1003 and A 1004 respectively type the formulae =average(A2:1001) and =stdevp(A2:A1000).
Copy these formulae into the adjacent cells in Column B.
What are the mean and standard deviations of the normal distribution you have produced?
Are they close to 0 and 1 respectively?
Save your file with a name like Standard normal 1.
Exercise 2 Creating a useful macro
Open a new file and in A5:A10 type the numbers 1-6
Select any box in the region A6 – A9.
Record a macro by the following steps.
First make sure the current cell is somewhere in the range A6-A9
On the Menu select Tools, Macro&gt;, Record new macro.
Give it a name like CopyBlockDown with kas the shortcut key.
Under description type copies block down. Press OK.
An icon will appear including the word stop. Click the bottom right bit of this once to select relative
cell reference . This is most important.
Everything you do now will be recorded for future reference so take it slowly.
1. Press CTRL + SHIFT + 8 (This should select the entire block of six numbers.)
2. Press CTRL + C (This should copy the block to the clipboard.)
3. Press END + down arrow
4. Press down arrow
5. Press CTRL + v (This should paste the block.)
6. Click on the square dot on the Stop button to stop recording
You are now ready to use the macro you have recorded.
1. In E 1 type = RAND() and in F 1 type = norminv(E1,0,1)
2. copy the formulae to row 2
3 select cell E1
4. Press CTRL+k nine times.
What happens? To examine the Program you have created on the menu select Tools, Macros, Edit, and
your macro. Can you make any sense of it?
2
```