Fundamentals of Finance and Investment

2 downloads 0 Views 6MB Size Report
Furthermore, the concept was reinforced because investment management has evolved ... Statistica, Mathematica etc) the author's choice for Stata was driven by the ...... Construct the future value path of each cash flow and calculate the future ...
Fundamentals of Finance and Investment Management Using Stata

Muhammad Hasnain Yousaf Institute of Business Administration (IBA), Karachi State Bank of Pakistan

i

This Page is left blank intentionally

ii

Dedicated to my teachers, parents and friends

iii

Foreword The book represents a humble effort to familiarize students with the essential concepts of finance, portfolio and risk management. Though many interesting and comprehensive principal level books remain available on the subjects, author felt that combining both the theoretical as well as practical aspect had the potential for being the “one stop shop” for new students of finance. Furthermore, the concept was reinforced because investment management has evolved in line with the evolution of technology. With better machines and ever improving mathematical and statistical data packages, author felt the need for equipping students with the use of some data analysis package so that when they enter the industry, they have some basic to intermediate data analysis as well as programing skills. Skillset is one of the most vital factors that employers seek in a candidate. A typical employer seeks a candidate with maximum SEEK score. The term SEEK represents four critical hiring factors 1. School (Repute of Candidate’s Business or Economics School) 2. Education (What kind of education the candidate holds?) 3. Extension (Has candidate extended upon his/her academics -e.g. CFA,FRM etc-?) 4. sKillset (What kind of skills the candidate brings to the organization?) For a moment one can consider SEEK as portfolio of four securities. While some of these factors may not be in the control of a typical candidate (e.g. Financial/Academic constraints, Choice of School etc), there are areas where students can certainly excel vis-à-vis their peers. And Skill set

iv

is one of those crucial aspects. Acquisition of superior data management and analysis skills often differentiates a successful professional from an average one. The purpose of this booklet is to equip students with not only the necessary concepts in finance but also adequate programing skills to develop, implement and improve those concepts. While the book is titled as principal level, the programing skills are not. So the book should not be taken as principal level in at least programing. Notwithstanding the complexities of programing, the book works towards building the skillset from scratch and will use the easiest possible programming syntax for solving the discussed problems. Of course better and more complex syntaxes/programs can subsequently be developed by students and readers once they get comfortable with the basic programing skills. And to encourage innovation in programming, the booklet follows the “Open authorship” policy, if the students and readers develop a novel and more comprehensive syntax/program for solving a particular finance problem, the syntax/program can be published in future editions by the name of the contributor! Though many other data management and statistical packages remain available (e.g. R, Matlab, Statistica, Mathematica etc) the author’s choice for Stata was driven by the fact that programing in Stata is more close to natural syntax and thus students and readers may find it easier to pick things up more quickly. Furthermore, there remains a lot of scope for the use of Stata in financial applications.

v

CONTENTS Chapter 1: Introduction to Stata Programming ......................................................................................................... 1 What is Stata? ....................................................................................................................................................................... 1 Getting Started in Stata : .................................................................................................................................................. 1 How does Stata look like? ........................................................................................................................................... 1 Some Good Stata Materials. ....................................................................................................................................... 4 A Checklist Before Getting Started with Stata .................................................................................................... 5 Getting Started with Stata .......................................................................................................................................... 6 The Need for Labeling and Graphical Aids ........................................................................................................ 11 Prerequisites of a Good Data Label/graph ........................................................................................................ 12 Using commands related to conditions in Stata. ............................................................................................. 17 Documenting The Programing Using Do-Files ..................................................................................................... 19 Concluding Remarks........................................................................................................................................................ 21 Questions for Further Practice. ................................................................................................................................... 22 Chapter 2: Intermediate Programing Skills ................................................................................................................ 23 Looping ................................................................................................................................................................................. 23 While Loop ...................................................................................................................................................................... 23 Foreach Loop ................................................................................................................................................................. 29 Adding Conditional If/else sub loops in a Loop .............................................................................................. 35 Using Forvalues Loop ................................................................................................................................................. 38 Basics of Matrices ............................................................................................................................................................. 43 Generating Matrices in Stata: .................................................................................................................................. 43 Special Matrix Operations: ....................................................................................................................................... 46 Matrix Algebra and Operations .............................................................................................................................. 48 Basic Mata ............................................................................................................................................................................ 51 Starting Mata.................................................................................................................................................................. 52 Matrix Operations in Mata ....................................................................................................................................... 52 Chapter 3: Time Value of Money ..................................................................................................................................... 57 Why Time Value of Money is Essential? .................................................................................................................. 57 Simple Interest Rate ........................................................................................................................................................ 61 Simple Interest Rate Programing Using STATA .............................................................................................. 61 Compound Interest Rate:............................................................................................................................................... 65 vi

Programing multiple interest rates in compounding: .................................................................................. 68 Compounding Frequency: ........................................................................................................................................ 72 FV Scenario Analysis with Stata ............................................................................................................................. 76 Calculating PV of cash-flows: .................................................................................................................................. 80 Programing Annuities in Stata ............................................................................................................................... 82 Calculating Annuity with Mismatched Compounded Frequencies and Cash Flow Stream Separation ....................................................................................................................................................................... 86 Concluding Remarks ................................................................................................................................................... 91 Chapter 4: Project Evaluation Methods ........................................................................................................................ 92 Why Project Evaluation is necessary?...................................................................................................................... 92 Valuation Methods ........................................................................................................................................................... 92 Payback Period ............................................................................................................................................................. 93 Net Present Value ........................................................................................................................................................ 96 Internal Rate of Return ........................................................................................................................................... 110 Concluding Remarks ................................................................................................................................................ 125 Chapter 5: Equity Valuation And Financial Information Analysis.................................................................. 126 How and why can DCF analysis be applied to equity? ................................................................................... 126 Models of Equity Valuation ........................................................................................................................................ 127 Gordon Growth Model (Dividend Discount Model).................................................................................... 127 Gordon Growth Model With Terminal Price.................................................................................................. 135 Valuation Using Multiples ..................................................................................................................................... 147 Price to Earnings Ratio (P/E)............................................................................................................................... 148 Target Price Determination And Comparison Based on Price Multiples (P/E) .............................. 156 Concluding Remarks ................................................................................................................................................ 159 Chapter 6: Fixed Income Valuation ........................................................................................................................ 160 World Bond Market: ................................................................................................................................................ 160 Valuation of Fixed Income Instruments: ......................................................................................................... 160 Valuation Using Stata: ............................................................................................................................................. 161 Price Yield Relationship:............................................................................................................................................ 165 Types of Bonds: .............................................................................................................................................................. 168 Pay out frequency: .................................................................................................................................................... 168 Payout Linkage: ......................................................................................................................................................... 168 Issuer: ............................................................................................................................................................................ 168 vii

Optionality: .................................................................................................................................................................. 169 Pricing Bonds with Options:...................................................................................................................................... 169 Callable bonds: ........................................................................................................................................................... 169 Putable Bonds: ........................................................................................................................................................... 169 Convertible Bonds: ................................................................................................................................................... 169 Bond Price and Other Attributes: ....................................................................................................................... 173 Rates Simulation: ........................................................................................................................................................... 179 Spot Rates: ................................................................................................................................................................... 179 Forward Rate .............................................................................................................................................................. 182

viii

PART 1 DEVELOPING BASIC SKILL SET FOR STATA

1

Chapter 1: Introduction to Stata Programing

CHAPTER 1: INTRODUCTION TO STATA PROGRAMMING WHAT IS STATA? Stata is a statistical package developed by the Stata Corporation. To date, 13 versions of Stata are available with latest being the Stata 13th. However, the programing available in this book can be implemented by using any version beyond Stata 8. Though generally “considered” lagging to specialized counterparts. The Stata is at least as versatile as any other available software and potential of developing programs is limitless. Though generally used in statistical and econometric applications, Stata does possess good mathematical as well as programming capabilities for programing and applications of Financial, Portfolio and Risk Management. In this chapter, we will try to develop the basics of general data management, while in Chapter 2 we will introduce ourselves to intermediately difficult topics like iterative programming, derivatives etc.

GETTING STARTED IN STATA : HOW DOES STATA LOOK LIKE ? Upon installation, you should see the following Stata Icon upon your desktop

1

Chapter 1: Introduction to Stata Programing

As the number indicates, the first icon is for Stata 11.0. In case a student installing Stata 12 and 13, slightly different yet easily recognizable icons should appear on your desktop. Once you double click or right click and “open” the program icon, the following interface should appear before you. For versions 8 to 11, you should be getting this kind of interface

The view contains an output box (colored in green and black), a command box situated below the output window. A variable view in bottom left box while a command history in upper left box. A slightly enhanced interface is available in Stata 12 onwards where in addition to these

2

Chapter 1: Introduction to Stata Programing

four boxes; an additional box for variable properties is also available for quick variable formatting.

The good news is that despite differences in the appearance and functionality (enhancement of functions as Stata evolves), the programming syntax remains essentially the same. So the programming developed in older versions works fine with the new ones. Another good news is that ample material remains available with respect to programming and data management in Stata (not only for basic but also advanced levels.) This makes getting help much easier.

3

Chapter 1: Introduction to Stata Programing

SOME GOOD STATA MATERIALS. While Google itself can lead to a lot of material on how to use Stata for data management. However, some of these sources contain pretty detailed discussions and practices.  Princeton University Data and Statistical Services  Institute for Digital Research and Education (IDRE)-UC at LA  J.F.K School of Governance, Harvard U  Notes on Stata by Alexander C. Lembcke-LSE o

Introduction

o

Advanced

 A brief introduction to Stata with 50+ basic commands (Tobias Pfaff)  An introduction to Stata by Mike Anderson  Couple of useful slides on programming Loops o

Looping in Stata

o

An Introduction to Stata for Econometric Analysis by Marina Bellani

Aside from these openly available notes, there are very good textbooks available on the subject. Some of the useful books which author has consulted so far include.  Introduction to Modern Econometrics using Stata by Christopher F Baum  Basic Econometrics with Stata by Carl E Moody  Introduction to Time Series Using Stata by Sean Becketti  A Visual Guide to Stata Graphics, 3e by Michael N. Mitchell  Using Stata for Principles of Econometrics, 4e by Lee C. Adkins and R. Carter Hill While these are all good reference materials, author considers three aspects crucial for a good grasp of programming in any statistical/mathematical package.

4

Chapter 1: Introduction to Stata Programing  Practice is necessary for perfection and improvements in programming syntaxes.  Comments and explanations of a particular syntax are often very helpful.  Documenting and Storing certainly helps a lot for future purposes.

A CHECKLIST BEFORE GETTING STARTED WITH STATA Few tips that students and readers can use before starting to use Stata.  Try to always document your work by using Do-files  Some of the good resources on creating and working with do-files are provided below o

Using Do-file editor by Miwa Nakajo

o

Using the Do-file Editor (Stata Manual)

o

Using Stata Do-Files by David Dranove

 Start with simple structures to understand the function of a particular program or Stata module. As you get comfortable with it, then of course you can try to incorporate more complexities.  Often there are multiple ways to go about a particular problem in Stata. So it is useful to expand the understanding of different syntaxes which lends more flexibility to a programmer.  If you feel stuck on a particular problem, it’s always good to use Google since more often if you’re stuck on a particular problem, somebody else would also have faced such a situation. So there is a very good chance that you might be able to find an answer to your problem. 

If you’re not able to find any help despite using Google, you can join some of the following for a/lists to get answers from experienced/more competent users o

Harvard Statalist (Better have a dedicated email id for subscription)

o

Stata Forum on Talk Stats

o

Absolute Austronomy (Stata section)

o

Stata forum.de (The drawback is that the forum is managed in German language)

o

Stackoverflow

5

Chapter 1: Introduction to Stata Programing  If any further help is required for the detailed structure of a particular function, the help command provides access to related material available in Stata manual. For example, If I want detailed help regarding the syntax and options of a function – Say replace- I can just type help replace to get instant access to information about the function in Stata Manual.  On a personal note, author would advise students to join some academic/general forum as such fora help students a lot in improving skills for structuring and improving their argument(s).

GETTING STARTED WITH STATA Data input, import and use: Though it is always useful to provide comprehensive details about the syntax and use of different functions/commands available in Stata, doing so will effectively convert this booklet into a booklet on Stata rather than its application. So author will assume a “learn as you perform” approach. This will familiarize the readers with the basic/extended syntax. For further details, readers can always solicit help using means discussed above. Stata uses *.dat as default format for its stata files. The data files saved by Stata end up with a *.dat extension. However, Data can also be inputted either manually or by importing from other file formats (raw data ACII, CSV format of excel etc). If the user is using a small dataset, it can be manually inputted by using the following commands

Example 1.1: 1. Creating a variable x with 10 observations 2. Replacing first three observations with values 1,2 and 3

Program Syntax Firstly I would create a memory of 10 observations by using set obs command set obs 10

6

Chapter 1: Introduction to Stata Programing Now in second step, I would create a variable with 10 missing values by using generate/gen command. gen x=. This will create a variable named x with 10 missing values. “.” Value, when assigned to Stata, is treated as a missing value. We can also create a variable x with values zero by assigning “0” to x. Now the custom values can be assigned in required cells to the variable x by using replace command. replace x=1 in 1 This will replace the missing value of x in first cell i.e. replace the missing value of first observation with value 1. Likewise this process can be repeated to create the values of choice . Furthermore in order to create a string variable (Qualitative Variable e.g. Names, Cities, Type etc), we can repeat the process with some additions. Suppose we want to generate a string variable “y” we will do the following gen y=. This will again create a variable named “y” with 10 missing values (since observations are set to be 10) Now we will change the format of the variable to string variable by using “tostring” command tostring y, replace Now we will replace the missing values with string format. 7

Chapter 1: Introduction to Stata Programing replace y = "" if y == "." Now we are ready to provide string input to the variable. Suppose I want to add a value “auto” to first cell, I will again use the replace command replace y = "auto" in 1 Now we can replace the observations with string values.

Exercise 1.1: Do the following 1- Generate 100 observations 2- Generate a trend variable x using gen command 3- Generate a variable y with values 0 4- Replace the values of 3rd,20th,34th,49th,65th,72nd,83rd,91st and 97th values with 1,2,3,4,5,6,7,8 and 9 respectively. 5- Generate a variable z with missing values 6- Convert the variable into a string variable 7- Add string values of Copper ,Steel, Iron, Sodium, Magnesium, Chlorine, Germanium, Plutonium,

Palladium,

Titanium

and

Sulphur

with

missing

values

of

1st,11th,21st,31st,41st,51st,61st,71st,81st and 91st observation. If data is available in raw or semi processed form ( i.e. available on Excel) students can also copy the data from excel file and then simply paste it in data editor (edit mode). If the data already contains variable names then student can select “treat first row as variable name” option. However, students are advised to perform number formatting in excel to “general” or “number” format before copying the data from excel. Often Sata doesn’t recognize the number format and resultantly, assigns string format to variable.

8

Chapter 1: Introduction to Stata Programing Moreover, if data is available in *.ASCII or *.CSV format, the data can be directly imported using insheet command. Note that before using insheet ensure that data file is in proper format. For example, MS Excel uses *.xls (and *.xlsx in modern versions) as default format. The students would have to use “save as” option and then change the extension to “Comma Separated/*.csv” extension. Once the file has been successfully converted into csv format, it can be imported using insheet command.

Example 1.2: Following are the steps for using insheet command in Stata. When Stata is initiated, the path of current directory can be seen on the bottom left corner. Further, reader can also retrieve the path by using cd command. cd The Stata returned the file path D:\Hasnain Folder\stata\Stata11 The reader can save the file in the said directory. If the file is already saved there, reader can also check the available files by using dir command dir Stata should return the list of files in the current directory as a result of dir. For example, I have a file named mus02file1.csv saved in my current directory and I want to import the data available in that file. I would use the insheet command insheet using mus02file1.csv

9

Chapter 1: Introduction to Stata Programing Furthermore, if the file is saved elsewhere Stata can import the data given the complete file path is provided insheet using “D:\Hasnain Folder\stata\Stata11\mus02file1.csv” If the data file is available on web in prescribed format, data can also be imported off the web using same command. For example, some sample datasets are available on Stanford website . Suppose I want to get the data containing crime statistics for each U.S. state from 1960 to 2005. The dataset is available as CrimeStatebyState.csv. inhseet command can be used to import the data directly off the web. insheet using “http://hci.stanford.edu/jheer/workshop/data/crime/CrimeStatebyState.csv” Notice that file path has been replaced with the path on the web. In addition, webuse command can also be used to get data off the web in the form of *.dat format. The structure is similar to that of current director (cd) command. The default path for webuse is http://www.statapress.com/data/r11/ . More details about the command are available in Stata help. More often, we further useful information can be created from current data. A variety of generation functions are available in Stata. The most common command is gen or generate. This generates a variable with specified value or function. The function of gen has already been discussed in example 1.1. Another command used by Stata to generate a scalar value (not a variable) is scalar. A value generated through scalar is stored by stata yet not considered as a variable. The scalar command often helpful in Data Generation Processes (DGPs) and performing calculations. The syntax of scalar is identical to generate. Furthermore, when working with large number of scalar values, a list of scalar values generated can also be accessed using scalar list command Some examples of scalar command as follow

10

Chapter 1: Introduction to Stata Programing Generating a constant scalar scalar x=5 this would generate a scalar x with a value of 5 Generating a scalar of two or more functions scalar y=sin(45)/cos(45) y will effectively generate a value of tan(45) Generating a scalar from particular observations of a variable scalar m=x[2]/y[2] m will be a scalar value generated from the division of second observations of variables x and y (variable generated using gen command)

THE NEED FOR LABELING AND GRAPHICAL AIDS One of the key purpose of research and data analysis is to provide the maximum possible information at minimum cost to the intended users. Therefore, often it’s very helpful to use different tools which would help researcher/programmer in achieving this goal. Furthermore, often readers find it more difficult to grasp the mere data. Graphs, thus provide the intended users with the necessary details with minimum effort required. Like the five C’s of communication, a good program/data analysis should 1. Clearly state what is its intended purpose? 2. Be reasonably concise 3. But be complete in what it wants to convey (Notwithstanding the need for conciseness)

11

Chapter 1: Introduction to Stata Programing 4. Be Coherent. The programing syntax or data analysis structure show follow the logical flow of underlying theoretical model (which it attempts to apply or simulate). This is an essential of programming since it is much easier to grasp things in logical order than a disordered syntax. An essential element of good data analysis and programing is that it should be presentable. For example, if the programmer is presenting his data analysis/programming to his/her peers, (s)he may find it easier to just present the syntax and discuss results. However, if the results are to be presented to “non-technical” like sales team –Which is often responsible for pushing the research/program in the market– or the management of the corporation, then it is often necessary to use various aids since graphs/data labels help 1. To understand the properties of underlying data or model. 2. To understand the prevailing/notable patterns. 3. To suggest the modeling strategies. 4.

To allow non-technical staff to provide their input on improvements to data analysis/ models.

PREREQUISITES OF A GOOD DATA LABEL/GRAPH Data labels help provide the complete description of variables. A good label should be able to communicate 1. What is the name of underlying variable? 2. What are the basis –if any– of the variable (e.g. Real Yield, Base Index etc)? 3. What is the underlying unit of measurement (e.g. %,USD,000’s etc)? Likewise, a good graph often contains 1- An appropriate name/number 12

Chapter 1: Introduction to Stata Programing 2- A title 3- Appropriate labeling of variables on respective axis. 4- Appropriate re-scaling if multiple variables are drawn together. 5- A legend containing the details of variables (if multiple variables are selected). 6- Text boxes containing necessary information (e.g. Source of Data, important notes etc). An example of good and bad labeling and graphing.  Setting up 20 observations using set obs command set obs 20  Generating a uniform random variable between 0 and 1 using gen command gen y=runiform()  Converting variable into 1000s using replace command (for rescalling) replace y=y*1000  Now generating a new variable y with a trend gen x=_n  Now plotting both variables unsing twoway command twoway (line y x) The following graph is obtained

13

0

200

400

y

600

800

1000

Chapter 1: Introduction to Stata Programing

0

5

10 x

15

 Now we provide appropriate labels to the variables using label command label variable y "Nominal Share Price (US Dollars)" label variable x "Trend (Years)" 

We plot a graph by providing necessary details

twoway (line y x), title("Graph 1: Share Price of ABC Corp")  This provides the following graph

14

20

Chapter 1: Introduction to Stata Programing

0

200

400

600

800

Nominal Share Price (US Dollars)

1000

Graph 1: Share Price of ABC Corp

0

5

10 Trend (Years)

15

20

Now this graph provides better information so as to what do the variables mean and what does this graph explains. Labeling can be applied to not only variables (discussed above) but also to the values of a quantitative variable for classification purpose (more useful when dealing with survey analysis)

Commonly used graphs in Stata Though various types of graphs are available in Stata, some of the most common ones available are summarized below. For more details, readers can always access help in Stata. Twoway command is used to create a variety of 2D graphs in Stata. The command utilizes the Stata’s graphic engine to generate elegant and customizable graphs. Note that plot command can also be used to generate in-Stata graphs but the graphs generated by using plot command do not use graphics engine and thus cannot be customized using graphics editor. The typical syntax of twoway command as follows twoway ((type of graph) (Y variable) (X variable(s))),options for graph for example, for a scatter of two variables Y and X the syntax will be

15

Chapter 1: Introduction to Stata Programing twoway (scatter y x) Likewise the following graphs can be generated using

Trends and Confidence Intervals  For Linear fit and CI use twoway (lfitci y x)  For Quadratic fit and CI use twoway (qfitci y x)  For Functional Polynomial fit and CI use twoway (fpfitci y x)  For Local Polynomial fit and CI use twoway (lpolyci y x)

Other Graphs  For Box-Plot(s) twoway (box y x)  For Line Plot(s) twoway (line y x)  For Bar Plot(s) twoway (bar y x)  For Dot Plot(s) twoway (dot y x)  For Spike Plot(s) twoway (spike y x)

Other Important Graphs Aside from twoway, the following are important graphing commands available in Stata  For histograms use histogram/hist command hist y x  For density plot use kdensity command kdensity y x  For time series plots tsline command plots line plot of selected variables over time (tsset command is a prerequisite)  Similarly for panel xtline command plots line plot(s) over panel over time (xtset command is a prerequisite) Like said before, these are just some of the plots commonly used. For more detailed understanding of different plots A Visual Guide to Stata Graphics, 3e (Michael N. Mitchell) is an excellent resource.

16

Chapter 1: Introduction to Stata Programing

USING COMMANDS RELATED TO CONDITIONS IN STATA. Often in finance and research, the events are conditional upon some restriction(s) or condition(s). In stata if command can be used to attach conditions to underlying processes. For example if we require a variable named taboo with value zero against a trend variable. Subsequently we declare a particular cell value to a value (say 2) we will use the following code

Example 1.3: The following code will be used clear cd set obs 100 suppose we want to generate a yearly variable named time beyond 1950 gen time = y(1950) + n-1 format time %ty tsset time Now let us generate a new random variable say x gen x=runiform() Suppose we want to generate a variable, say y, and then change certain cell values according to some condition(s) being met, we can use the conditions in replace command to do the same For example, gen y=0

17

Chapter 1: Introduction to Stata Programing Now in order to apply a condition, Stata recognizes the following operands. Table 1.1: Using Conditions in Data operations Operand == > < >= 1950 replace y=3 if time=1952 replace y=0 if time=1952 & time1 & `j'=1 & `i'=1 & `i'=2 & `i'=`=`=firstperiod'+1' & `i'=`=`=secondperiod'+1' & `i'=2 & `i'=2 & `i'=2 & `i'=`=y'{ scalar PV`s'`k'`i'=(FP`s')/(1+(`k'/100))^`=y'

174

Chapter 6: Fixed Income Analysis scalar CPV`s'`k'`i'=PV`s'`k'`i'+CPV`s'`k'`=`i'-1' replace PV`s'=CPV`s'`k'`i' in `k' } } } } twoway (line PV`=u'-PV`=v' Yld),title("Example 6.5: Bond Price-Yield Relationship with variation in coupon", box size(small))

0

500

1000

1500

2000

Example 6.5: Bond Price-Yield Relationship with variation in coupon

0

20

40

YTM (%)

5%($) 7%($) 9%($) 11%($)

60

80

100

6%($) 8%($) 10%($)

The figure tells us that changing coupon rate does not affect the P-Y relationship other than shifting the curve up i.e. a liner relationship. After this, we will try investigating the standalone relationship of Coupon and Maturity, holding yield constant. Exercise 6.6: We shall now compute the impact of change in coupon rate on bond price. clear scalar drop _all cd *Assigning the Input values scalar P=1000 175

Chapter 6: Fixed Income Analysis scalar r=0.30 scalar y=10 scalar u=1 scalar dif=1 scalar v=50 scalar CPF=P*0.01 *Soluation *Calculating Present Value set obs `=v/dif' gen CPN=_n/`=dif' gen PV=. label variable CPN "Coupon Rate (%)" label variable PV "Bond Price ($)" forv k=`=u'(`=dif')`=v'{ scalar cpn`k'=`k'*CPF scalar FP`k'=cpn`k'+1000 forv i=1/`=y'{ if `i'