/
EViews Training Data Objects: Data Functions EViews Training Data Objects: Data Functions

EViews Training Data Objects: Data Functions - PowerPoint Presentation

cheryl-pisano
cheryl-pisano . @cheryl-pisano
Follow
342 views
Uploaded On 2019-11-22

EViews Training Data Objects: Data Functions - PPT Presentation

EViews Training Data Objects Data Functions Note Information for examples in this tutorial can be found in these files Data Dataxlsx Results Resultswf1 Practice Workfile Datawf1 Data and Workfile Documentation ID: 766618

gdp series command functions series gdp functions command sample window show type enter cumulative press moving period statistic data

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "EViews Training Data Objects: Data Funct..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

EViews Training Data Objects: Data Functions Note: Information for examples in this tutorial can be found in these files. Data: Data.xlsx Results: Results.wf1 Practice Workfile: Data.wf1

Data and Workfile Documentation Data.wf1 and Data.xlsx have the following data: Workfile Page: Timeseries (Data.xlsx tab Timeseries): quarterly, Q1 1980 – Q1 2012 GDP – real GDP data (billions of dollars) from the Bureau of Economic Analysis. PCE – real consumption data (billions of dollars) from the Bureau of Economic Analysis. Inv – real private sector investments (billions of dollars) from the Bureau of Economic Analysis. G – real government spending (billions of dollars) from the Bureau of Economic Analysis. y – a series that grows over time (trend series). 2

Data Functions EViews has a large number of built-in functions that allow you to perform data manipulation. EViews functions are typically denoted by the symbol “ @ ”.This tutorial reviews some typical functions used for data manipulation, such as: Random numbers Statistical Functions Commonly Used Time Series Functions 3

Generating Random Numbers

Generating Random Numbers (Series): Example 1 You can generate a series of (pseudo) random numbers drawn from a variety of distributions. There are a number of ways to generate a random series. Generating a random series: Example 1 Open EViews workfile Data.wf1. Select Quick → Generate Series from the main menu. Type y1 = nrnd in the dialog box and press Enter. 5

Generating Random Numbers (Series): Example 1 (cont’d) The result is shown here. As seen, this generates a series y1, which is normally distributed with mean 0 and standard deviation equal to 1. 6

Generating Random Numbers (Series): Example 2 Alternatively, you can create a random series by typing in the command window. 7 Generating a random series: Example 2 Type in the command window: series z= nrnd Press Enter . This creates a new series z , which is normally distributed with mean 0 and standard deviation equal to 1 .

Generating Random Numbers (Series): Example 3 Suppose you want to simulate a random walk process with distribution properties similar to the observed distribution of an existing series (for example, gdp):8 Generating a random series: Example 3 Type in the command window: smpl @all series newdata = 0 smpl 1980q2 @last newdata = newdata (-1)+@ mean(d( gdp ))+@ stdev (d( gdp ))*nrndPress Enter after each command line. Note: for an explanation of statistical functions @mean, @stdev, or d(gdp), see Descriptive Statistics in this tutorial.

Generating Random Numbers (Series): Example 3 (cont’d) Here we show both the new series ( newdata ) and the GDP series. As seen, the command has generated a series newdata, which follows the same distribution process as the gdp series.Note that the commands instruct EViews to first create a new series (newdata) consisting of zeros. Then, from the second observation (1980q2) onwards it sums the preceding observation with the mean and standard deviation of differenced gdp (multiplied by a normal random variable). 9

Generating Random Numbers (Series): Common Functions/Commands Common Commands/Functions 10 Function/Command Description series y= nrnd or (y=@ rnorm ) Normal distribution (mean 0, st. dev. 1) series y=3+@sqr(4)*nrndNormal distribution (mean 3, variance 4) series y=@rlognorm(1,4)Lognormal distribution (mean=1, st. dev 4) series y=@ runif (1,3) Uniform distribution on (1,3) series y= rnd Uniform distribution on (0,1) series y=1+(3-1)* rnd Uniform distribution on (1,3) (same as @ runif (1,3)) series y= rndint(0,100)Fills series y with random integers drawn randomly from 0 to 100 EViews has a number of functions/commands that allow you to draw from a variety of distributions. The most commonly used functions/commands are summarized below.

Generating Random Numbers (Series): PDF and CDF 11 Function Description series d1 = @ runif (0,2) show d1 @ dunif (d1,0,2) @cunif(d1,0,2)Creates d1 as uniform distribution on (0,2) Displays series d1 created above, pdf of d1 and cdf of d1 It is also very easy to generate the pdf and cdf of a random variable. Generating a random series together with its pdf and cdf : Type in the command window: smpl @all series d1=@ ruinf (0,2) show d1 @ dunif (d1,0,2) @ cunif (d1,0,2) Press Enter after each command line.

Generating Random Numbers (Series): PDF and CDF (cont’d) 12 The result is shown here. As you can see, EViews displays all three columns: the actual new random variable we created ( d1 ), its density function (in the second column) and its cumulative distribution function (third column).

Functions for Descriptive Statistics

EViews has extensive built-in descriptive statistical functions. These descriptive statistical functions take an optional sample as an argument. The default sample is the current workfile range. 14 Descriptive Statistics

15 Function Description series y=@ gmean(x) Computes the geometric average of X series y=@mean(x) Creates a series where each observation is equal to the mean of X series y=@mean(x,“1980m01 1990m12”) Creates a series where each observation is equal to the mean of X for the defined sample (1980m01 to 1990m12) series y=@median(x) Creates a series where each observation is equal to the median of X series y=@vars(x)Computes the sample variance of X (adj. by n-1) series y=@ varp (x) or y=@ var (x) Computes the population variance of X (adj. by n) series y=@ stdev (x) or y=@ stdevs(x) Computes the sample st. dev. of X (adj. by n-1) series y=@ stdevp (x) Computes the population st. dev. of X (adj. by n) Common Commands/Functions Descriptive Statistics Common Commands/Functions

Descriptive Statistics Functions: Example 1 Suppose you want to create a series x1 , which is equal to the mean of the “gdp” series. 16 Descriptive Statistics Functions: Example 1 Type in the command window: series x1=@mean( gdp ) Press Enter . This creates a new series x1 which has all elements equal to the mean of GDP.

Descriptive Statistics Functions: Example 2 As a next example, consider creating another series x2 , which is equal to the mean of the “gdp” series, defined over several sub-samples: 17 Descriptive Statistics Functions: Example 2 Type in the command window: smpl 1980q1 1989q4 series x2=@mean(gdp, "1980q1 1989q4") smpl 1990q1 1999q4 series x2=@mean(gdp, "1990q1 1999q4") smpl 2000q1 @last series x2=@mean(gdp, "2000q1 @last") smpl @all Press Enter after each command line.

Descriptive Statistics Functions: Example 2 (cont’d) 18 The result is shown here. For ease of exposition, we plot the graph of the series. As you can see, EViews has created a step-wise function defined over the various samples as we specified in the command line.

Descriptive Statistics Functions: Example 3 Suppose you want to create a variable which is the average (or sum) of multiple series. 19 Descriptive Statistics Functions: Example 3 1a. One way to do this is to type the following in the command window : series new=( gdp+pce+inv )/ 3 1b. Another way, would be to type in the command window group row functions: group groupdata gdp pce inv This creates a new group (named “ groupdata ”) with containing the three series. 2b. Now type the following command in the command window: series new=@rmean(groupdata) This creates a series which is computed by taking the mean of all the three series for each row. Press Enter after each command line.

Descriptive Statistics Functions: Example 4 Suppose you want to collect descriptive statistics in a vector (or matrix). 20 Descriptive Statistics Functions: Example 4 Let’s first define the sample over which descriptive stats are computed. Type in the command window: smpl 1980m01 1990m12 Next, let’s create a vector v by typing in the command window: vector(3) v Next, define the vector elements to gather the desired statistics, by typing in the command window: v(1)=@ mean( gdp ) v(2)= @ varp ( gdp ) v(3)= @covs(gdp,pce)Press Enter after each command line.

Explanations of commands/functions for Example 4 Note that the optional sample argument may only be used if the results are assigned to a series. For example: series y=@mean(x[,s]) – where s is the sample, allows you to define the sample as the last argument of the descriptive statistic function.If results are assigned into a matrix, vector or scalar object (as in example above), the sample needs to be defined explicitly before using the descriptive statistical functions. 21 Descriptive Statistics Functions: Example 4 (cont’d) Function Description smpl 1980q01 1990q04 Defines the sample over which descriptive stats are computed vector(3) v Creates a vector v with 3 elements v(1)=@mean( gdp ) Assigns the first element of the vector v to equal the mean of gdp over the defined sample v(2)=@ varp(gdp)Assigns the second element of the vector v to equal the population variance of gdp (adj. by n) v(3)=@ covs ( gdp,pce ) Assigns the third element of the vector v to equal the sample covariance between gdp and pce (adj. by n-1)

Common Time-Series Functions (Lags/Leads, Differences, Percent Change, Moving Statistics, Trends)

Lags & Leads It is easy to work with lags/leads and other time series functions in Eviews . You do not need to generate series of lags/leads in many places in EViews; simply write the command for them when needed (i.e., when estimating a regression). 23 Function Description gdp(-4) Denotes the 4 th lag of the GDP series gdp(2) Denotes the 2nd lead of the GDP series gdp (-1 to -4) Specifies all GDP lags from 1 to 4gdp(to -5) OR gdp (0 to -5) Specifies all GDP lags from 0 to -5 series y = @lag(gdp,3) Generates series y, as the 3 rd lag of GDP series y =@lag((gdp- inv )/gdp,4) Generates series y, as the 4 th lag of the transformation ( gdp-inv )/gdp Common Commands/Functions

Lags & Leads: Example 1 Create and show the 4 th lag of the variable gdp. 24 Lags & Leads: Example 1 Type in the command window: s mpl @all show gdp gdp (-4) Press Enter . Note that this creates a new group which contains both the gdp series and its fourth lag (we requested that both series appear) If you would like to save the group, click the button and name the group.

Lags & Leads: Example 2 Create and show the 2 nd lead of the variable gdp. 25 Lags & Leads: Example 2 Type in the command window: show gdp gdp (2) Press Enter . Note that this creates a new group which contains both the gdp series and its 2 nd lead (we requested that both series appear) We have saved and named the group ( group 04 ).

Lags & Leads: Example 3 You can just as easily create a number of lags in EViews For example, you may show the actual value and all first three lags of gdp. 26 Lags & Leads: Example 3 Type in the command window: show gdp (0 to -3) Press Enter . Note that this creates a new group which contains the gdp series and all lags from 1 to 3. The group is saved as group 05 .

Lags & Leads: Example 4 You can also create a series as a lagged transformation of other series. 27 Lags & Leads: Example 4 Type in the command window: s eries newseries =@lag(( gdp-inv ) /gdp,4) Press Enter . Note that the new series is first computed as: ( gdp-inv )/ gdp . Then, the fourth lag is taken.

Differences: Example 1 EViews has several build-in functions for working with differenced data (levels and logs). 28 Function Description d(gdp) = gdp - gdp(-1) Takes the first difference of the GDP series Differences : Example 1 Type in the command window: show d( gdp ) Press Enter . Note that for comparison purposes here we have shown both the d( gdp ) series and another series where the difference is computed manually ( gdp-gdp (-1)). As seen, they are the same.

Differences: Example 2 Log-difference: 29 Differences : Example 2 Type in the command window: show dlog(gdp) Press Enter . Function Description dlog (gdp) = log(gdp) – log(gdp(-1)) Takes the first difference of log(GDP) series

Differences: Example 3 EViews also allows you to take higher order differences (of levels and logs): 30 Differences : Example 3 Type in the command window: show d(gdp,3) Press Enter . Function Description d(gdp,3) 3 rd order difference of GDP series ( (1-L) 3 X ) ( Note : This is NOT the same as X-X(-3 ); it is X-3X(-1)+3X(-2)-X(-3 ))

Differences: Example 4 Higher-order differences in logs 31 Differences : Example 4 Type in the command window: show dlog(gdp,4) Press Enter . Function Description dlog (gdp,4) 4 th order difference of log(GDP) series ( (1-L) 3 log(X ).

32 Function Description d(gdp,1,4) 1 st order differences with seasonal difference in lag 4 d(gdp,0,4) Captures only seasonal difference (at lag 4) You can also take seasonal differences after specifying both ordinary and seasonal difference terms: Seasonal Differences

Percent Change EViews also has a number of functions dealing with percent changes. Common Functions 33 Function Description @pc(gdp) calculates the one-period percent change in GDP (in percent) @ pch (gdp) calculates the one-period percent change in GDP (in decimal) @ pca (gdp) calculates the one-period annualized percent change in GDP (in percent) (1+@ pch (x)) n -1 (where n=4 for quarterly data, n=12 for monthly, ect)@pcha(gdp)calculates the one-period annualized percent change in GDP (in decimal) @pcy( gdp ) calculates the one-year percent change (in percent) @pchy(gdp) calculates the one-year percent change (in decimal)

Percentages: Example 1 Calculate the percent change in gdp from the previous period. 34 Percentages : Example 1 Type in the command window: show @pc( gdp ) Note that @pc shows the percent change in percent. If you would like to compute it in decimals, type in the command window: show @ pch ( gdp ) Press Enter . Note that we instructed EViews to display both series ( @pc( gdp ) and @pch(gdp)) in the same group. The group is saved as group06.

Percentages: Example 2 Calculate the annualized one-period percent change in gdp . 35 Percentages : Example 2 Type in the command window: show @ pca ( gdp ) Press Enter . Note this computes the annualized percent change in the quarterly (one-period) gdp data. This is the same as: 100*( (1 +@ pch ( gdp )) 4 -1) .

Percentages: Example 3 Calculate the year-over-year percent change in gdp . 36 Percentages : Example 3 Type in the command window: show @ pcy ( gdp ) Press Enter . Note this computes the one-year percent change in gdp data. In quarterly data (which is the case here), t his is the same as: 100* (gdp t+4 -gdp t /gdpt).

Cumulative Statistic Functions Cumulative functions perform “running-total”-type calculations. For these functions the length of the window changes with each observation. 37 Common Functions Function Description @ cumsum ( x,s ) Cumulative Sum of the values in X over sample s @ cumprod ( x,s ) Cumulative Product of the values in X over sample s@cummean(x,s)Mean of the values in X over sample s up to and including current observation@cumobs(x,s)The number of non-missing observations in X from over sample s @ cumbsum ( x,s ) Backwards cumulative sum of the values of X over sample s beginning with the end of the sample @cumbmean(x,s) Backwards cumulative mean of the values of X over sample s beginning with the end of the sample up to and including current observation@cumbstdevBackwards cumulative standard deviation of the values of X over sample s beginning with the end of the sample up to and including current observation

Cumulative Statistic Functions: Example 1 Show the cumulative sum for series y over a pre-defined sample. 38 Cumulative Statistic: Example 1 Type in the command window: show @ cumsum (y,"1980Q3 1981Q4 ") Press Enter . Note that to facilitate comparisons, we have shown both the original ( y ) series and the new cumulative sum defined over the specific sample. The cumulative sum series is calculated by adding the values from the start of the sample to the current value. The cumulative sum starts at the beginning of the sample (1980Q3) and ends at the end of the sample (1981Q4). Original series @cumsum(y,s)

Cumulative Statistic Functions: Example 2 Show the cumulative backward sum for series y over a pre-defined sample. 39 Original series @cumbsum(y,s) Cumulative Statistic: Example 2 Type in the command window: show @ cumbsum (y ,"1980Q3 1981Q4 ") Press Enter . The backward cumulative sum series is calculated by adding the values from the end of the sample to the current value . Note that, unlike the previous example, the backward cumulative sum starts at the end of the sample (1984Q1) and ends at the start of the sample (1980Q3).

Cumulative Statistic Functions: Example 3 Show the cumulative mean of series y over a pre-defined sample. 40 Original series @cummean(y,s) Cumulative Statistic: Example 3 Type in the command window: show @ cummean (y ,"1980Q3 1981Q4 ") Press Enter . The cumulative mean series is calculated from the start of the sample (1980Q3) until the current observation.

Cumulative Statistic Functions: Example 4 Show the cumulative standard deviation of series y over a pre-defined sample. 41 Original series @cumstdev(y,s) Cumulative Statistic: Example 4 Type in the command window: show @ cumstdev (y ,"1980Q3 1981Q4 ") Press Enter . The cumulative standard deviation is calculated from the start of the sample (1980Q3) until the current observation.

Moving Statistic Functions These types of functions have shorter, fixed, user-specified window lengths. They provide information on n observations (including the current observation).The window length n is chosen by the user.If the original data has missing values (NA), results may or may not propagate NA. 42 Generic Function Description @ mov [ specified statistic ] This command generates missing values @ m [ specified statistic ] This command skips NA observations and does not generate NA values

43 Function Description @ movav(x,n) n-period backwards moving average (if n=3, X+X(-1)+X(-2)/3). NA s are generated @ movav (x(-1),n) n-period backwards moving average (if n=3, X+X(-1)+X(-2)/3) lagged by one period. NAs are generated @movsum(x,n) n-period backwards moving sum (if n=3, X+X(-1)+X(-2)). NAs are generated@movvar( x,n ) n-period backwards moving variances: population variance for the current and previous n-1 observations . NA s are generated @ mav (x,n) n-period backwards moving average (if n=3, X+X(-1)+X(-2)/3). NAs are NOT generated @ msum ( x,n ) n-period backwards moving sum (if n=3, X+X(-1)+X(-2)). NAs are NOT generated@mvars(x,n)n-period backwards moving sample variance: sample variance for the current and previous n-1 observations. NAs are NOT generated Moving Statistic Functions (cont’d) Common Functions

Moving Statistic Functions: Example 1 Show a 4-period moving average for series y . 44 Original series @movav(y,n) Moving Statistic: Example 1 Type in the command window: show @ movav (y,4) Press Enter . Note that the 4-period backwards moving average is computed as: (X+X (-1)+X(-2 )+X(-3))/4.

Moving Statistic Functions: Example 2 You can combine operators (functions) to perform more complex examples. Suppose you would like to show the 4-period moving average for series y lagged by one period. 45 Original series @movav(y(-1),n) Moving Statistic: Example 2 Type in the command window: show @ movav (y(-1),4) Press Enter . The 4-period backwards moving average is computed as: (X+X (-1)+X(-2 )+X(-3))/4. This is then lagged by one period as we specified.

Moving Statistic Functions: Example 3 Show a 5-period backward moving sum for series y . 46 Original series @movsum(y,5) Moving Statistic: Example 3 Type in the command window: show @ movsum (y,5) Press Enter . Note that the 5-period backward moving sum is generated by adding: ( X+X(-1)+X(-2)+X(-3 )+X(-4)).

Moving Statistic Functions: Example 4 Show a centered 5-period backward moving sum for series y. 47 Original series @movsum(y(2),5) Moving Statistic: Example 4 Type in the command window: show @ movsum (y(2),5) Press Enter . Note that the 5-period backward moving sum is now centered at the observation which falls in the middle of the interval. It is computed by adding: (X(-1)+X(-2)+X+X(+1)+X(+2)).

Trends 48 Function Description@trend Time trend increasing with each observation @ trendc Calendar-based time trend (in irregular workfiles @trend and @ trendc return different results) @trend^2 Quadratic time trend increasing with each observation It is very easy to generate trends in EViews by using a number of built-in functions. Common Functions

Trends : Examples Create two trend series one with initial value 0 and the other one 1. 49 Trend1 Trend2 Generating Trends: Type in the command window: series trend1=@trend series trend2=@trend+1 Press Enter after each command. Note that @trend creates a series that begins at 0; while @trend+1 has initial value of 1.