Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Eviews5 / EViews5 / Example Files / docs / series

.htm
Скачиваний:
18
Добавлен:
23.03.2015
Размер:
8.51 Кб
Скачать

Sample Programs td.btop {border-top: 1px solid black} td.bbot {border-bottom: 1px solid black} td.bleft {border-left: 1px solid black} td.bright {border-right: 1px solid black} td.center {text-align:center} td.left {text-align:left} td.right {text-align:right} td.bottom {vertical-align:bottom} td.underline {text-decoration:underline} td.strikeout {text-decoration:line-through} td.indent1 {text-indent:1} td.bgcolor {background-color:#000000} td.ftcolor {color:#000000} hr.width100 {width: 100%} hr.black {color:#000000} td.btop {border-top: 1px solid black} td.bbot {border-bottom: 1px solid black} td.bleft {border-left: 1px solid black} td.bright {border-right: 1px solid black} td.center {text-align:center} td.left {text-align:left} td.right {text-align:right} td.bottom {vertical-align:bottom} td.underline {text-decoration:underline} td.strikeout {text-decoration:line-through} td.indent1 {text-indent:1} td.bgcolor {background-color:#000000} td.ftcolor {color:#000000} hr.width100 {width: 100%} hr.black {color:#000000} Series  The following examples show the use of the EViews programming language to perform the following tasks: Calculate cumulative sums (cum_sum.prg) Compute lags on a broken sample of observations (subset.prg) Create dummy variables with a loop (make_dum.prg) Calculate cumulative sums EViews does not have a built-in function for calculating cumulative sums. You can easily calculate such sums with a few lines of commands. Say we have a series X for which we would like to calculate the cumulative sum. If the series does not contain NAs, you can use:

smpl @first @first series sum0 = x smpl @first+1 @last sum0 = sum0(-1) + x If the series does contain NAs, you have two options, depending on how you would like the NAs to be treated. If you would like to continue accumulating the sum, ignoring the NA observations, you can use:

smpl @first @first series sum1 = @nan(x,0) smpl @first+1 @last sum1 = sum1(-1) + @nan(x,0) smpl @all if x = na sum1 = na If you would like to reset the sum to zero whenever an NA appears in the series you can use:

smpl @all series sum2 = x smpl if sum2(-1)<>na and x<>na sum2 = sum2(-1) + x The complete program is as follows:

' three rules to compute cumulative sums with missing values 'create workfile wfcreate cumsum u 1 10 'fill data series x x.fill 4,2,na,4,1,3,2,na,7,5 'for series without NAs smpl @first @first series sum0 = x smpl @first+1 @last sum0 = sum0(-1) + x 'ignore NAs smpl @first @first series sum1 = @nan(x,0) smpl @first+1 @last sum1 = sum1(-1) + @nan(x,0) smpl @all if x = na sum1 = na 'reset to zero at NAs smpl @all series sum2 = x smpl if sum2(-1)<>na and x<>na sum2 = sum2(-1) + x smpl @all show x sum0 sum1 sum2 The following sample output shows the differences between the three methods:

                           

^Top

Compute lags on a broken sample of observations Many operations in EViews can be performed on a subset of the workfile observations using the smpl command. To estimate an equation using only observations which have a positive value of X, you could use:  smpl if x>0 eq1.ls y c x Time series operations often rely on observations being adjacent, so that this method may not work as expected. In this example we demonstrate a general technique for working with a subset of observations from the workfile as though they were adjacent. There are three steps to using the method:  create a “short version” of the data which contains only the subset of observations. 

use the “short version” of the data to get whatever results you need.

create a “long version” of the results which match the observations in the original data.

Consider the simple case of creating a series which contains the differences between consecutive positive values of the series X, ignoring any intervening negative values. 

The commands:

smpl if x>=0 series dxp = d(x) will not compute the desired values, since the d function computes differences between adjacent values, not between successive values in the sample. The SUBSET.PRG program solves this problem using the general technique outlined above. The solution is stored in the series DX. The series X_S and DX_S are left in the workfile so you can follow the intermediate calculations.

' time series operation on subsamples ' create workfile wfcreate subset u 1 10 ' fill data series x x.fill 4,2,na,4,1,3,2,na,7,5 ' create sample sample ss if x<>NA and x>=0 ' create short x series smpl @all vector temp stomna(x, temp, ss) series x_s mtos(temp, x_s) !rows = @rows(temp) 'save number of elements delete temp ' difference short x series series dx_s = d(x_s) ' map back into long series dx vector temp stomna(dx_s, temp) vector(!rows) temp 'trim to number of elements series dx mtos(temp, dx, ss) delete temp ' display results show x dx x_s dx_s ^Top

Create dummy variables with a loop It is sometimes useful to create a set of dummy variables for a range of observations in a workfile. You can then include one or more of these dummies in an estimation simply by adding their names to the list of exogenous variables. It is easy to create these series by hand, though somewhat tedious. The program MAKE_DUM.PRG automates this task. It should be run from the command line with arguments for the first and the last observation for which to create dummies. For example, to create dummies in a quarterly workfile from the first quarter of 1982 to the last quarter of 1983, the command would be:

run make_dum 1982:1 1983:4 As is, the program should work for annual, semiannual, quarterly, monthly and undated workfiles. It should be modified for weekly and daily workfiles.

' create dummy variables for every observation in sample 'create workfile wfcreate dumtest q 1970 1990 'set up start and end dates %start = "1972:1" 'first observation to dummy %end = "1979:4" 'last observation to dummy 'generate dummy variables from 'start' to 'end' for !i = @dtoo(%start) to @dtoo(%end) 'string containing observation offset %obsstr = @otod(!i) 'name of dummy if (@mid(%obsstr, 5, 1) = ":") then %name = "d_" + @left(%obsstr, 4) + "_" + @mid(%obsstr, 6) else %name = "d_" + %obsstr endif 'generate dummy series smpl @all series {%name} = 0 smpl {%obsstr} {%obsstr} series {%name} = 1 next smpl @all show d_* ^Top

Соседние файлы в папке docs