/* Data is taken from Bank of Canada's Website http://www.bankofcanada.ca/rates/interest-rates/lookup-bond-yields/ V39059: Government of Canada marketable bonds - average yield - 1 to 3 year 05-08-2011 to 06-01-2012 Note that some observations are missing due to Bank Holidays (what should you do?) */ clear cd "/Users/pabsta/Documents/2-Enseignement/ECON452/tutorial3/" set mem 15m use ORIGINALDATA/BOCGovernmentBonds.dta log using "OUTPUT/tutorial2-2.txt", replace t /* Basic descriptive statistics and Time operators*/ // TIME OPERATORS //Stata must know that you work on a dataset where the order of observation is not random. //Most time-series commands will not work if you do set the time variable. tsset date //indicates Stata that time is indexed by this variable. //Dates can have multiple format see the commands "date" and "format" for more. //Once the date is set, some commands implicitely take this variable as an argument: tsline yield //The command tsreport tells if there are missing observations: tsreport, report //The command "tsfill" fills missing dates in the sample with empty observations tsfill //LAG OPERATOR //One can create a lag variable with the Lag operator: gen yield_lagged = L.yield //one period lag gen yield_lagged2 = L2.yield //two periods lag, etc. //FORWARD OPERATOR gen yield_forward = F.yield //You can use this directly in a regression command: reg yield L.yield L2.yield //AR(2) spec //DIFFERENTIATION OPERATOR gen diff_yield = D.yield //diff_yield[t] = diff_yield[t] - diff_yield[t-1] //SEASONNAL OPERATOR /* There is another operator, S.varname, that can be applied for seasonnal differences. It is similar in nature do the difference operator, except that the difference is taken by seasons. */ // DESCRIPTIVE STATISTICS //The command "sum" summarizes statistics on a series: sum yield //Adding the option details is also helpful sum yield, detail //The command "tab" is the "on-screen" equivalent of an histogram tab yield hist yield // PARTIAL AUTOCORRELATION AND AUTOCORRELATION FUNCTIONS //Commands that we will use extensively are the following //Autocorrelation function //(We have not seen this yet in class.) ac yield //Partial autocorrelation function //(We have not seen this yet in class.) pac yield //On screen equivalent of the two last commands corrgram yield //Getting the Aikake criterion as well as the Schwartz criterion for AR models //(We have not seen this yet in class.) varsoc yield // IF COMMANDS /* It is sometimes useful to condition commands on subsamples. For instance, one might want to keep the most recent values to evaluate the forecasting performance of the model. Hence, one can think of commands being performed only on observations below some date or within some range. To illustrate the purpose, we will use the command "count" which counts the number of observations. For instance the command "count" let alone will count the total number of observations (including missing obs). */ count //Now, if we want to count only observations that are missing, we write: count if( yield == .) //Note the double equality sign which is the symbol for "logically equal" /* The logical symbols are : == which means "logically equal to" >= which means "greater or equal to" <= which means "smaller or equal to" ~= which means "not equal to" */ count if(date<=d(05082011)) //no obs count if(date > d(05082011)) //All but one count if(date == d(05082011)) //One obs /* To indicate a range, you need to understand composite conditions. For instance, the following command: */ count if(date>=d(01082011) & date<=d(31082011)) //All observations in august 2011 /* The symbol "&" is the logical AND. So the previous condition is: "count all observations if the date is higher (or equal) than the first of august 2011 and below (or equal) the 31st" The symbol "&" allows for composite conditions : take two conditions together and take them as true. If we have two conditions joined by an "&", say c1 & c2, the command will be executed only on observations where c1 and c2 are true. There is another logical symbol that allows for composite conditions: "|" (a vertical bar). This symbol stands for "OR", so only one of the two conditions has to be true. For instance: */ count if(dated(31082011)) //All observations not in August 2011 log close