Working with Date Functions in EViews: A Comprehensive Guide

Slide Note
Embed
Share

Explore the powerful built-in date functions in EViews, including functions like @year, @quarter, @month, @day, and more. Learn how to create date-related dummy variables efficiently using these functions. The tutorial provides detailed instructions and examples for working with dates in EViews workfiles.


Uploaded on Sep 08, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. EViews Training Date Functions Note: Data and workfiles for this tutorial are provided in: Results: Results.wf1 Practice workfile: Data.wf1

  2. Basic work with Date Functions

  3. Data and Workfile Documentation Data.wf1 has a number of workfile pages (note there are no data in any of the pages). Workfile Page Annual: structured page, annual frequency, 1960 - 2010. Workfile Page Quarterly: structured page, quarterly frequency, 1960q1-2010q4. Workfile Page Monthly: structured page, monthly frequency, 1960m1-2010m12. Workfile Page Daily: structured page, daily frequency (weekday), 1960/01/01-2010/12/31. 3

  4. Date Functions EViews has some very powerful built-in functions that allow you to easily work with dates in dated workfiles. Main Functions Function Description @year Returns the year in which each observation begins. @quarter Returns the quarter of the year in which each observation begins. @month Returns the month of the year in which each observation begins. @day Returns the day of the month in which each observations begins. @weekday Returns the day of the week. @hour Returns the hour of each observation as an integer. @minute Returns the minute of each observation as an integer. @second Returns the second of each observation as an integer. @seas(x) Returns a seasonal dummy variable. 4

  5. Date Functions (contd) Function Description @daycount Returns the number of days within each observation. Returns a dummy variable with value equal to 1 prior to the specified date. @before( date ) Returns a dummy variable with value equal to 1 after the specified date. @after( date ) @during( date1 date2 ) Returns a dummy variable with value equal to 1 for each observation between date1 and date2. @holiday Returns the proportion of an annual event (such as a holiday) that lies in each observation. 5

  6. Date Functions and Dummy Variables: Example 1 Date functions can be very useful when creating date-related dummy variables. Suppose you want to create an annual dummy variable which has the value of 1 post-1979 and 0 otherwise. Date Functions and Dummy Variables: Example 1 1. Open Data.wf1. Click on the Annual page. 2. Type in the command window: series y=@year>1979 3. Press Enter. Function Description series y=@year>1979 Series equals 1 post-1979 and 0 otherwise 6

  7. Date Functions and Dummy Variables: Example 1 (cont d) More easily, you could use the @after function to achieve the same result. Date Functions and Dummies: Example 1 (cont d) 1. Click on the Annual page. 2. Type in the command window: series y_Ev8=@after("1979") 3. Press Enter. Function Description Series equals 1 post-1979 and 0 otherwise series y_EV8=@after( 1979 ) 7

  8. Date Functions and Dummy Variables: Example 2 Likewise, EViews offers a number of easy-to-use functions that allow you to create date-related dummy variables. Suppose you want to create an annual dummy variable which has the value of 1 pre-1987 and 0 otherwise. Date Functions and Dummies: Example 2 1. Click on the Annual page. 2. Type in the command window: series x_ev8=@before("1987") 3. Press Enter. Function Description Series equals 1 pre-1987 and 0 otherwise series x_EV8=@before( 1987 ) 8

  9. Date Functions and Dummy Variables: Example 3 As an additional example, consider the case of creating a dummy variable which equals 1 between 1987 and 1994 and 0 otherwise. Again, we can create this indicator very easily. Date Functions and Dummies: Example 3 1. Click on the Annual page. 2. Type in the command window: series z_ev8=@during("1987 1994") 3. Press Enter. Function Description Series equals 1 between 1987 and 1994 series z_EV8=@during( 1987 1994 ) 9

  10. Date Functions and Dummy Variables: Example 4 Create a dummy variable equal to 1 for the month of January, and 0 otherwise. Date Functions and Dummy Variables: Example 4 1. Click on the Monthly page. 2. Type in the command window: series y=@month=1 3. Press Enter. Function Description series y=@month=1 Series equals 1 if month=January, 0 otherwise 10

  11. Date Functions and Dummy Variables: Example 5 Create a dummy variable equal to 1 if the day of the week is Friday, 0 otherwise. Date Functions and Dummy Variables: Example 5 1. Click on the Daily page. 2. Type in the command window: series y=@weekday=5 3. Press Enter. Function Description series y=@weekday=5 Series equals 1 if day=Friday, 0 otherwise 11

  12. Date Functions and Dummy Variables: Example 6 Create seasonal dummies for all four quarters of the year Date Functions and Dummy Variables: Example 6 1. Click on the Quarterly page. 2. Type in the command window: show @seas(1) @seas(2) @seas(3) @seas(4) 3. Press Enter. Function Description @seas(1), @seas(2) @seas(3), @seas(4) Creates 4 dummy variables for the four quarters of the year in a quarterly workfile 12

  13. More Advanced Work with Date Functions

  14. Date Arithmetic EViews provides several functions for manipulating dates more generally. EViews first converts a date string into a date number so that you can manipulate it. For example, EViews first converts January 1, 1999 into a numerical value (729754) which allows you to manipulate dates more generally. Main Functions Function Description Returns the day number for the start of this observation @date @dateadd Shifts a date forward or backward by a unit of time @datediff Calculates the difference between two dates in a unit of time @datefloor Rounds down a date to the beginning of a unit of time @dateval Converts a text date into a numerical value 14

  15. Date Arithmetic: Example 1 You can use @date and @dateval to create date-related dummy variables. Suppose you want to create a dummy variable in the monthly workfile which takes on the value of 1 for all dates prior to March 1980. Date Arithmetic: Example 1 1. Click on the Monthly page. 2. Type in the command window: series z=@date<@dateval("1980m03") 3. Press Enter. Function Description series z=@date<@dateval( 1980 m03 ) Series equals 1 pre-March 1980, 0 otherwise 15

  16. Date Arithmetic: Example 2 You can use @datediff to perform a number of date calculations. Suppose for example, you want to find the number of days (or business days) between 10/15/2007 and 3/1/1995). Date Arithmetic: Example 2 1. Click on the Monthly page. 2. Type in the command window: series x=@datediff(@dateval("10/15/2007"),@dateval("3/1/1995"),"d") 3. Press Enter. Use b for business days Function Description @datediff(d1, d2, u) Returns the difference between two date numbers d1 is the start date d2 is the end date u is the time unit d1 and d2, measured by the time unit u 16

  17. Date Arithmetic: Example 2 (cont d) Results for the number of days d and number of business days b are shown here. # of business days # of days Note: You can use any of the pages (annual, quarterly, monthly, etc.) in the Data.wf1 file for this example. All will produce similar results, calculating the difference (in either days or business days) between two dates. 17

  18. Date Arithmetic: Example 3 In a monthly dated file, find the number of days (or business days) in a month. Date Arithmetic: Example 3 1. Click on the Monthly page. 2. Type in the command window: series w=@datediff(@date(+1),@date,"d") 3. Press Enter. Use b for business days 18

  19. Date Arithmetic: Example 3 (cont d) Results for the number of days d and number of business days b are shown here. # of business days in the month # of days in the month 19

  20. Date Arithmetic: Example 3 (cont d) More easily, you could use the @daycount function. Date Arithmetic: Example 3 (cont d) 1. Click on the Monthly page. 2. Type in the command window: series dayEV8=@daycount 3. Press Enter. 20

  21. Date Arithmetic: Example 3 (cont d) You can use the function @daycount to perform a slightly different exercise. For example, you would like to count the number of Fridays that appear in a given month. Date Arithmetic: Example 3 (cont d) 1. Click on the Monthly page. 2. Type in the command window: series FridayEV8=@daycount("Friday") 3. Press Enter. 21

  22. Date Arithmetic: Example 3 (cont d) Likewise, you can use @daycount function to count the number of days in a month that fall in an interval defined by two weekdays (including those days). For example suppose you would like to count the number of days in a month that fall between Wednesday and Friday (including Wed. and Fri). Date Arithmetic: Example 3 (cont d) 1. Click on the Monthly page. 2. Type in the command window: series Wed_Fri_EV8=@daycount("Wednesday Friday") 3. Press Enter. 22

  23. Date Arithmetic: Example 4 In a monthly dated file, find the number of days (or business days) in a quarter. Note that this example is similar to Example 3, except that you cannot use @datediff(@date(+1), @date, d ), because the file is structured in monthly frequency and you are looking for the number of days in a quarter. Here is a more general approach in dealing with dates, regardless of the structure of the dated workfile. Date Arithmetic: Example 4 1. Click on the Monthly page. 2. Type in the command window: show @datefloor(@date,"q") 3. Press Enter. Note that this command instructs EViews to show the date at the beginning of the quarter. 23

  24. Date Arithmetic: Example 4 (cont d) Next, type in the command window: show @dateadd(@datefloor(@date,"q"),1,"q") 4. Press Enter. 5. Note that this command instructs EViews to show the date at the beginning of the next quarter. 24

  25. Date Arithmetic: Example 4 (cont d) Finally, type in the command window: show @datediff(@dateadd(@datefloor(@date,"q"),1,"q"), @datefloor(@date,"q"),"d") Press Enter. Note: Please make sure that the above command is typed in one line in the command bar. Note also that this command instructs EViews to find the difference (in days) between the dates found in steps (2-3) and those found in steps (4-5). 6. 7. # of days in the quarter 25

  26. Date Arithmetic: Example 5 You can use @dateadd and @datediff function to find the number of days remaining until the end of the month, or the number of days that have elapsed since the start of the month. Let s illustrate how to find the number of days until the end of the month. Date Arithmetic: Example 5 1. Click on the Daily page. 2. Type in the command window: show (@dateadd(@datefloor(@date, "m"),1,"m")-@date) OR show @datediff(@dateadd(@datefloor(@date, "m"),1,"m"),@date,"d") Press Enter. 3. 26

  27. Date Arithmetic: Example 5 (cont d) The result is shown here. Note that this shows the number of days between a given date until the end of the month. If you want to find the number of business days until the end of the month, you should type b instead of d at the end of the command. Note also that the first portion of the command(@dateadd(@datefloor(@date, "m"),1,"m")), instructs EViews to find the first date of the next month, while -@date subtracts the current date from the next month s first value. # of days until the end of the month 27

  28. Date Arithmetic: Example 6 Let s find the number of days since the beginning of the month. Date Arithmetic: Example 6 1. Click on the Daily page. 2. Type in the command window: show (@date-@datefloor(@date,"m")) If instead, you would like to find the number of business days since the start of the month, type: show @datediff(@date, @datefloor(@date,"m"), "b") Press Enter. 3. 28

  29. Date Arithmetic: Example 6 (cont d) Results for both actual days and business days are shown here. # of days since the start of the month # of business days since the start of the month 29

  30. Date Arithmetic: Example 7 You can also use the @date function to create dummy variables that pick out the first or the last day of the month (or quarter). Date Arithmetic: Example 7 1. Click on the Daily page. 2. Type in the command window: series x=@datefloor(@date, "m")<>@datefloor(@date(-1), "m") 3. Press Enter. Note: Please make sure that the above command is typed in one line in the command bar. If you wanted to create a dummy variable for the last day of the month, type in the command window: series x1=@datefloor(@date, "m")<>@datefloor(@date(+1), "m") 30

  31. Date Arithmetic: Example 8 You can also use @datediff function to find out the week of the month. Date Arithmetic: Example 8 1. Click on the Daily page. 2. Type in the command window: show @datediff(@date, @datefloor(@date, "m"), "w")+1 3. Press Enter. Note that the command finds the difference (in weeks) between the current date and the date at the beginning of the month. The +1 is used so that the week count starts from 1 and not 0 . 31

  32. Date Arithmetic: Example 9 You can also use the set up of the previous example, to create a dummy variable for the first Monday of every month. Date Arithmetic: Example 9 1. Click on the Daily page. 2. Type in the command window: series w1=(@weekday=1 and @datediff(@date, @datefloor(@date,"m"),"w")+1=1) 3. Press Enter. Note: Please make sure that the above command is typed in one line in the command bar. If you wanted to create a dummy variable for the fourth Friday of the month, type in the command window: series w2=(@weekday=5 and @datediff(@date, @datefloor(@date, "m"), "w")+1=4) 32

  33. Date Arithmetic: Example 10 Building on the previous two examples, we can now create a dummy variable that picks out US Labor Day (which occurs on the first Monday of Sept.). Date Arithmetic: Example 10 1. Click on the Daily page. 2. Type in the command window: series w3=(@month=9 and @weekday=1 and @datediff(@date,@datefloor(@date, "m"), "w")+1=1) 3. Press Enter. Note: Please make sure that the above command is typed in one line in the command bar. 33

  34. Date Arithmetic: Example 11 Let s illustrate a slightly more complex example which is a combination of some of the previous examples. Suppose you would like to weight each monthly observation by the days in the month/normalized (divided by) the total days in the year. You can accomplish this in a few steps as shown here. Date Arithmetic: Example 11 1. Click on the Monthly page. 2. As a first step, let s find the number of business days in the month (similar to example 4 above). For this, type in the command window: series t1=@datediff(@dateadd(@datefloor (@date,"m"),1,"m"),@datefloor(@date, "m"),"b") Press Enter. 3. Note: Please make sure that the above command is typed in one line in the command bar. 34

  35. Date Arithmetic: Example 11 (cont d) Next, let s find the number of business days in the year by typing in the command window: 4. series t2=@datediff(@dateadd(@datefloor(@date,"y"),1,"y"), @datefloor(@date, "y"),"b") 5. Press Enter. Note: Please make sure that the above command is typed in one line in the command bar. 35

  36. Date Arithmetic: Example 11 (cont d) Lastly, let s form the weights by dividing t1 by t2, typing in the command window: series weights=t1/t2 6. 7. Press Enter. Note: The commands for this example are shown here: 36

Related


More Related Content