Вы находитесь на странице: 1из 13

Introduction to using Excel with Essentials Mathematics For Economic Analysis

In this chapter we briefly cover the basics of Excel and explain how to do elementary computations. If you have experience in using Excel, most of the material will be familiar. We only cover the aspects of Excel that are needed to be able to follow the later chapters in this booklet. If you have no experience with Excel at all, spend some time with one of the many guides to Excel that are available. Note that Excel comes in many versions. This booklet is based on Excel 2000 and for some of the material covered here, earlier and later versions of Excel may do things differently. When you open Excel for the first time you are presented with Excel's workspace. Figure 1 shows a screenshot. Don't let the complexity of the Excel workspace faze you. We will not use most of the things in the Excel workspace and the things we need will be explained to you as we go along. You will, however, need to know a few things. The first thing to notice is a grid with a large number of cells. The cell is the basic unit for input and output of calculations. Into the cells we enter numbers, formulas and view the result of our computations. Each cell has a reference that identifies it.

Formula Bar

Figure 1. The Excel Workspace

The cell in the upper left corner is A1. A refers to the column and 1 refers to the row. There are 256 columns and 65536 rows so there is plenty of space. The column numbering is somewhat unorthodox. The first 26 columns are referred to as A, B, , Z. The next 26 columns are referred to as AA, AB, , AZ. The next 26 columns are referred to as BA, BB, , BZ and so on. In Figure 1 we have entered 2 into the cells B4 and C4. This is done simply by selecting a cell with the mouse and typing 2. To select a cell, point the mouse at the cell and click with the left mouse button. 1 Next, select cell B4 and type =B2+C2. This formula
1

Some left-handed users may have set Windows to switch the functionality of the mouse buttons. If that is the case, click the right mouse button.

takes the arguments in B2 and C2 and adds them. The result, 4, is shown in B4. As long as cell B4 is selected we can see the formula generating the result in the Formula bar. Of course we could have entered =2+2 and found the same result. Which approach to choose depends on which calculations we want to do. Formulas can be almost as complex and as long as we want to, but complicated formulas quickly become hard to read. There are two ways of making complex formulas more transparent. One way is to write user defined functions in Excel's macro language Visual Basic for Applications. We illustrate how to do this in an appendix to this chapter. The other way is to perform intermediate calculations in a number of cells. Say, for example, that we have the formula x = (32 (5/2))2 and we want to find x. Entering =((3^2)-(5/2))^(-2) will compute x, but already this simple formula becomes hard to read in the formula bar. A more transparent way of doing this calculation is to enter =3^2 into the cell A1 and enter =5/2 into the cell B1 and then entering =(A1-B1)^(-2) into a third cell. Entering formulas like this makes the spreadsheet easier to read and easier to change. Since the number of available cells is huge (65536 rows 256 columns equals a total of 16777216 cells) you are unlikely to run out of space.2 Excel has built in all the elementary mathematical operations and using them is straightforward. In order to calculate 2 - 2 we can change the above formula to =B2-C2. Finding 2/2 can be done by entering the formula =B2/C2 and on Multiplying 22, by entering =B2*C2. To do powers we use the ^ symbol. Thus =2^2 is the same as 2 2 and Excel reports the result 4. Excel can also work with negative exponents. The Formula =2^(-2) gives n n the result 0.25. So does the Formula =1/(2^2) confirming the general rule that a = 1/a . Excel uses parenthesises in the same way as you would use parenthesises when making calculations with pen and paper. We can use parenthesises in Excel to determine the order in which calculations are done whenever this is important. For example, It is not clear what the 4 5 4 formula =3^4*5 means. Is it 3 or is it 3 5? It turns out that this formula returns 405 = 4 4 5 3 5. If you want to calculate 3 you must enter the formula =3^(4*5). Computer calculations follow certain conventions about the order in which different mathematical operators are performed. For those of us that have a hard time remembering these conventions, using parenthesises to specify the order reduces the likelihood of errors. As we all inevitably make mistakes, parenthesises are helpful when looking for them. You should, however, be aware that there is a quirk in Excel, which sometimes makes itself known when you are working with parenthesises. Occasionally, a formula like =-(A1)^2 will yield the same answer as =(C3)^2. It appears that Excel simply disregards the minus sign! What actually happens, is that Excel disregards the parenthesis and treats the formula as =-A1^2 and calculates a square of a negative number. Occasionally, we will want to refer to a range of cells. A range of cells is a rectangular set of cells. In Excel, the convention is to refer to a range of cells by specifying the cell in the northeast corner and the cell in the south west corner separated by a colon. Thus the range A1:B3 refers to the rectangular set of cells A1, B1, A2, B2, A3 and B3. Example 1. Compound Interest
2And

even if you did run out of space in one spreadsheet you can link your spreadsheet with other sheets. See the Excel documentation for details.

To illustrate the use of formulas in Excel we shall examine how to calculate compound interest. In EMEA, Chapter 1 the formula for calculating the value of an original investment K after t years when the interest rate is p% is given by: p K F 1 H 100I K
t

So, if our original investment is 100, the interest rate is 5% and we want to know the value of the investment after 10 years, we can enter the formula =100*(1+(5/100))^10 into a cell and the correct answer 162.8894 is reported. But, if we want to calculate the value of our investment for several values of t, it is easier to enter the formula in such a way that we can easily change parameter values. Figure 2 illustrates one way of doing this.

Figure 2. Spreadsheet for Compound Interest Calculations

In Figure 2, the compound interest formula is entered in cell C9. You can see the formula in the Formula bar. The number of periods are given in cell D9 as t = 5. So, if we want to find the value of the investment after 10 years, we simply change the value of the cell D9 to 10. The new result appears immediately and is equal to 162.8894. A large number of mathematical functions are built into Excel and you can enter them directly into a cell. Excel has a tool called the Function Wizard that helps the user find the function she wants to use. If we want to calculate , we can do this by using an in-built function that calculates square roots. Put the number 144 into the cell A1, Then select cell B1. Next, go to Insert on the menu and click Function. Excel will then open a dialog box. This dialog box is illustrated in Figure 3. The dialog box has two lists. The list on the left gives different function categories. Since a square root is a mathematical function, select this category. The list on the right gives a list of all functions belonging to the selected category. It is important to note in particular, that the list contains the function SQRT. Select this function. After selecting SQRT, some text appears in the bottom left corner of the dialog box. This text confirms that SQRT is the function that Excel uses to calculate square roots and gives the syntax of the function. The syntax of a computer function is a description of what arguments the function needs and in what order the arguments should be entered. In this case, the syntax is easy. Any single number or formula that returns a single number will do.

Figure 3. The Insert Function Dialog Box

Press Ok. Then a new dialog box appears. This dialog box is shown in Figure 3. Here we can enter the number 144 directly, or we can insert a reference to the cell containing the number 144. In this case the cell reference is A1 so we simply write this cell reference into the dialog box as shown in Figure 4.3 Clicking Ok gives the result 12 in the cell B1.

Figure 4. Entering arguments for functions

You should try to enter a negative number as an argument. Although a negative number obeys the syntactic rules for the function, the function will return a #NUM! message. This is an error message that tells you that an unacceptable argument has been used in a function.

An alternative way of entering the cell reference is to click on the little grid next to the text box where you enter the arguments. You can then select the cells that contain the argument to the function.

The number of arguments that a function requires depend on what the function does. The function =pi() requires no arguments. It simply returns the number The function . =power(arg1;arg2) returns arg1 raised to the power of arg2. Thus =power(2;3) returns 23 = 8. Note: The arguments of the function =power(arg1;arg2) are separated by a semicolon (;). This may not be the case for all readers. For some users the arguments may be separated by a comma. This depends on what of character is set as the list separator in Regional Settings in the Control Panel in Windows.4 What setting is used on each individual PC can be altered by the user. The default depends on what language your Windows version is. For the same reason some users may find that a comma rather than period is used to indicate a decimal holder. Throughout this booklet we use period as a decimal holder and semicolon to separate arguments in functions. Another function that you will need is the exponential function, =exp(arg) where arg is any number and =ln(arg) which returns the natural logarithm of its argument. You can also define composite functions. Say, for example, that you want to calculate elnx for different values of x. (Maybe to confirm numerically that elnx = x for all x > 0.) In order to create a formula that does this, simply type =exp(ln(arg)) into any cell and let arg be either a number or a cell reference. For instance, =exp(ln(2)) returns 2. Exercises 1) Calculate (3-2 2/3)1.5. 2) Calculate the present value of $200 that is deposited in a bank account for a period of 10 years at interest rate 5%. 3) Find the function in Excel that returns the absolute value of a number and use this function to calculate |-3|. 4) Calculate x3 for x = 0, 1, 2, 10 by using the power function. ,

Numbers in Excel Excel works with numbers, but since Excel is a computer program there are restrictions on the kind of numbers that can be represented. Excel only works with numbers that obey the following restrictions:

The largest number that Excel accepts is 1.7976931348623110308 The smallest (in the sense that it is the most negative) number that Excel accepts is 1.7976931348623110308 No number can have more than 15 decimals. Non-zero decimals after the 15th are automatically converted to zero. Excel will usually report answers with even fewer decimals rounded up or down. E.g. =2/3 will be reported as 0.666667.

Obviously Excel cannot accurately represent irrational numbers because of the upper limit of 15 decimals. Indeed, most of the rational numbers cannot be accurately represented either.
4

Assuming that the system uses Microsoft Windows.

The limitations on size and the number of decimals will rarely be important for economists, although astronomers will occasionally have to redefine their units in order to get around the limitations on magnitude and number of decimals.5

Logical Functions and Relational Operators There are some relational operators and logical functions in Excel that you should be aware of. Relational operators A relational operator in Excel is a function that compares two mathematical expressions. Examples of such relational operators are >, =, and Because some of these symbols are . not available from the keyboard, Excel uses alternative ways of typing them into a cell. The Excel syntax is shown in Table 1. These operators may be entered directly into Excel. The formula =(2 > 1) entered into a cell returns True since 2 is indeed larger than 1. The formula =(2 <= 1) entered into a cell returns False, since 2 1 does not hold. Similarly, the formula =(1+1 <> 2) returns False, since 1+1 = 2.

Table 1. Relational Operators in Excel Operator > < = Excel equivalent > < = <= >= <>

Logical Functions Logical Functions are extremely important in programming. They are similar to implications in mathematics and have many of the same properties. The main difference is that logical operators only check the truth content of a premise and assign values to additional statements conditional on the truth value of the premise, whereas mathematical implications derive additional statements that are true. As an example, write the formula =if(1+1=2; "The moon is made of cheese") into a cell. The function if() evaluates the truth content of the first argument, finds that 1 + 1 = 2 and returns the message "The moon is made of cheese". Obviously this is not a true statement, but it is the message that the =if() function is required to return if the premise 1 + 1 = 2 is found to be true. There are several logical functions that are supplied within Excel. We explain three of the most useful. The if statement The if statement has the following syntax.
5Admittedly,

astronomers tend to use other programs than Excel anyway.

= if(logical_test,value_if_true,value_if_false) Here logical_test is the premise or the assertion that we want to check. value_if_true is the is returned value if logical test is true and value_if_false is the returned value if logical_test is false. The last argument is optional. Example 2 2 Examine if > 10 by using an if-statement. Solution: Enter the formula =if(PI()^2 > 10;True, False) into a cell. The value FALSE is 2 returned, verifying that < 10m since 9.87. The Not Statement The not statement has the following syntax: not(logical) Logical is a statement that is either true or false. Example 3 Evaluate whether 52 43 > 0 is false using a not statement. Solution Enter =not(5^2-4^3 > 0) into a cell. The cell returns the value TRUE indicating that 52 43 > 0 is false. The Or statement The Or statement is used to examine if at least one of a number of assertions is true. Syntax OR(logical1,logical2,...) Logical1,logical2,... are 1 up to to 30 conditions you want to test that can be either true or false. Example 4 Examine whether at least one of the following propositions are true using an or() statement.
2 > 9

5 2 43 > 0

Solution. Enter the following formula into a cell: =OR(PI()^2>9;5^2-4^3>0) . The cell 2 returns the value TRUE so at least one of the propositions is true. (Indeed 9.87) Exercises

Evaluate the proposition 1/x > with an if statement, and make the statement return 10 if the statement is true and -10 if the statement is false. Evaluate the proposition for x = 1, 2, 3, 4, 5. Solution: Enter the numbers 1, 2, 3, 4 and 5 into the cells A1 to A5. Then enter the formula =if(1/A1>0.25;10;-10) into cell B1. Then copy the content of cell B1 into cells B2 to B5. The cell B2 to B5 returns the answer 10 and the rest returns 10.

Defining and Plotting Functions of One Variable The concept of a function is a fundamental part of computerized calculations. Indeed, every cell in an Excel spreadsheet may be considered a potential function, in the sense that we enter input into the cell and see the output that the input produces. Consider the function f(x) = x2. We can enter the formula =A1^2 into cell B1. Then the content of cell B1 becomes a function of the content of cell A1. Enter the number 2 into cell A1. The result is 4. By using Excel's graphing capabilities, we can get a pretty good idea about what this function looks like. To do this, first copy the content of B1 into B2. Then write the formula =A1+0.25 into the cell A2. Then copy the content of the cells A2:B2 into the cells A3:B17. The result should look like Figure 5. In Figure 5, the numbers in column A are x values and the numbers in column B are y = x2. E.g. for x = 0.75 in cell A12, the corresponding value of x2 = 0.752 = 0.5625. We now use these numbers to draw a graph of x2. First select the cells in A1:B17. Then go to the Insert menu. Choose Chart. This starts the Chart Wizard that guides you through the steps of creating a chart. In the list Chart Type, choose XY (Scatter). From Chart sub-type, choose any type that connects the data with smoothed lines.

Figure 5. f(x) = x2 At this point the dialog box should look like Figure 6.

Figure 6, Selecting Chart Type. Then click Next. The Chart wizard then takes you through a number of steps that allow you to format your chart so that it looks the way you want it to. After completing the Chart Wizard, you can format the chart further by adding/removing background colour, choosing fonts and so on. You should consult an Excel Manual for details. The graph of x2 is shown below in Figure 7 for my personal choice of formatting options.

4.5

3.5

2.5

x2
2

1.5

0.5

0 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5

Figure 7, f(x) = x2

Example 5. The cost of producing x units of a product is given by C x 100x x 500 Plot C(x) for the interval [0, 20]. Solution Enter 0 into cell A1 and =100*A1*sqrt(A1)+500 into B1. Then enter =A1+1 into cell A2. Copy the content of A2 into cells A3:A21 and copy the content of B1 into cells B2:B21. Use the Chart wizard as described above to create the chart. Depending on the choice of formatting options, the resulting chart should look like Figure 8.

10

10000

9000

8000

7000

6000

C(x)

5000

4000

3000

2000

1000

0 0 5 10 15 20 25

Figure 8. C(x) = 100x+500

Defining Functions in Visual Basic for Applications There is an alternative way of defining functions in Excel. Especially if the functions are complicated, they can be hard to read when they are defined in a cell. In these cases, it may be beneficial to define functions in Visual Basic for Applications, (VBA). This is Excel's version of the widely known programming language Basic. The version of Basic used in Excel is specially designed to be used as a macro language, but it remains a full-featured programming language. For our purposes we only need to know how to write functions. In order to illustrate, say that we want to define a function f(x, y) = x2 + y2 and use this function to calculate f(2, 2) = 22 + 22 in a spreadsheet, we first start Excel, then select Tools on the menu and find the item Macro. Next, select Visual Basic Editor.

11

Figure 9. Defining functions in VBA Alternatively, after starting Excel press <Alt> + <F11>. This will start a new program that gives access to all active Excel macros. In order to define a function we must create a module. This is done by selecting the menu item Insert, and then selecting the sub-item Module. Take care not to insert a Class Module, since this will not work. It will open an area where text may be entered. After entering the function definition, the Visual Basic Editor should look something like Figure 9. After doing this, we can return to the spreadsheet by closing the Visual Basic editor. Entering =f(2;2) into any cell returns the correct value 8.

Summation in Excel In EMEA you have been introduced to the summation symbol The use of this symbol is . often convenient. There is an equivalent function in Excel. Say, for example, that we have a set of numbers in the range A1:A4 and we want to compute the sum of these numbers in cell A11. We could write this sum as the formula =A1+A2+A3+A4, but it is much more convenient to us the =sum() function. The argument of the =sum() is a range, so we can enter the formula =sum(A1:A4). This is illustrated in Figure 10.

Figure 10. The summation function

12

In fact, you could have done this by first selecting cell A5 and then clicking the button. Excel would then correctly guess what numbers you are trying to sum and automatically enter the formula. Relative versus absolute cell references An important feature in Excel is that a cell reference can be absolute, relative or a mix of both. The distinction is important when we copy formulas from one cell to another. An absolute reference to cell A1 is written $A$1. If we copy a formula from one cell to another, the formula will always refer to cell A1. However if we copy a formula with a reference to cell A1 without the dollar signs, the reference in the new cell will depend on which cell we copy the formula to. To illustrate this lets use the example that we want to create a column of cells such that the content of the top cell is zero, the next cell is 0 + 0.25, the next is 0 + 2 0.25, the next is 0 + 3 0.25 and so on. In short, the number in row i is 0.25 added to the number in row i 1. To accomplish this, first enter the number zero in A1 and 0.25 in B1. Next, write the formula =A1+$B1$ in cell A2. Then copy the content of A2 into the range A3:A5. In Figure 11 you will see how the formulas look in the different cells.

Figure 11. Relative and absolute cell references In cell A3, the relative reference to A1 in the original formula has been automatically changed to A2, whereas the absolute reference to B1 remains the same. You are encouraged to examine the properties of relative and absolute cell references in the Excel documentation.

13

Вам также может понравиться