講義參考講稿variables_第1頁
講義參考講稿variables_第2頁
講義參考講稿variables_第3頁
講義參考講稿variables_第4頁
講義參考講稿variables_第5頁
已閱讀5頁,還剩42頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、EViews TrainingDummy Variables Note: Data and workfiles for this tutorial are provided in: Data: Data.xlsx Results: Results.wf1Practice Workfile: Data.wf1 Data and Workfile DocumentationData.wf1 and Data.xlsx consist of two pages (tabs) with the following data: Workfile Page: Dated (Data.xlsx tab Da

2、ted): daily, from Jan 1, 1950 August 2, 2012 Volume S&P 500 volume (source: St. Louis Federal Reserve Bank, FRED Database) Volume1- percent change in S&P500 Volume Return S&P 500 return (source: St. Louis Federal Reserve Bank, FRED Database) Workfile Page: Cross_Section (Data.xlsx tab Cross_Section)

3、 data on 526 individuals wage wage per hour (in dollars) educ number of years of education exper experience, number of years female dummy variable, equal to 1 if female, 0 otherwise married dummy variable, equal to 1 if married, 0 otherwise2* This data is from Wooldridge, Introductory Econometrics (

4、4th Edition). Data Series Objects: Series and Groups It is fairly easy to create dummy variables in EViews by using sample commands or a number of EViews functions:smplrecodedateexpandThis tutorial demonstrates how to create: Dummy Variables using samples Dummy Variables using the recode function Da

5、te Dummy Variables using the date function Categorical Dummy Variables using the expand function3Creating Dummy VariablesUsing SamplesCreating Dummy Variables Using Samples: Example 1 The easiest way to create dummy variables in EViews is by using samples (smpl command).Lets illustrate a few example

6、s using the Dated page in Workfile Data.wf1. Suppose you would like to create a dummy variable equal to 1, if return0.2, and 0 otherwise. 5Dummies with samples: Example 1Open Data.wf1 workfile. Click on the Dated page. Type in the command window:smpl if return0.2series dummy1=1smpl if return0.3, or

7、return0.3 or return-0.3 and return0.3 series dummy2=0Press Enter after each command line. Original Series Dummy VariableCreating Dummy VariablesUsing recode functionCreating Dummy Variables Using recode Another way to create dummy variables in EViews is by using recode function. 9FunctionDescription

8、recode(s,x,y)Returns x if condition s is true; otherwise it returns yCreating Dummy Variables Using recode: Example 1 10You can create the dummy variables in the examples above by using recode. Suppose you want to create a dummy equal to 1 if return=0.2, 0 otherwise. Dummies with recode: Example 1Cl

9、ick on the Dated workfile page. Lets first set the sample equal to the entire range by typing in the command window smpl all. Now, type in the command window: series dummy4=recode(return=0.2,1,0)Press Enter. Alternatively:Click on the top menu bar of and select Quick Generate Series. The Generate Se

10、ries by Equation dialog box opens up. Specify here your dummy expression (as shown here). Click OK. Creating Dummy Variables Using recode: Example 1 (contd) The original series (return) and the new dummy variable are both shown here. Original series Dummy Variable11Creating Dummy Variables Using rec

11、ode: Example 212Create a dummy variable equal to 1 if -0.2return-0.2 and return1,1,0)Press Enter. Original Series Dummy VariableCreating Dummy Variables Using recode: Example 313Create a dummy variable equal to 1 if return=1, 0 otherwise. Dummies with recode: Example 3Click on Dated workfile page. T

12、ype in the command window: series dummy6=recode(return=1,1,0)Press Enter. Original Series Dummy VariableCreating Dummy Variables Using recode: Example 4 14Suppose you would like to create two new series by separating an existing series (return) as follows; series1 collects values of return for which

13、 -0.3return0.3series2 collects values of return for which return=0.3Dummies with recode: Example 4Click on Dated workfile page. Type in the command window: series series1=recode(return-0.3 and return0.3,return,0) series series2=recode(return0.3,return,0)Press Enter after each command line. Creating

14、Dummy Variables Using recode: Example 4 (contd)15 The original series (return) and the two new dummy variables are shown here. Original series Series 1 Series 2Creating Dummy Variables Using recode: Example 516Lets create a total return index from the daily S&P500 returns. Dummies with recode: Examp

15、le 5Click on Dated workfile page. Type in the command window: series index=recode(trend=0,100, index(-1)*(1+return/100)Press Enter. Original Series IndexCreating Dummy Variables Using recode: Example 617Lastly, suppose you want to create a series that excludes outliers from the return series.Specifi

16、cally, suppose that the new series excludes the highest and the lowest 2.5% values of returns. Dummies with recode: Example 6Click on Dated workfile page. Type in the command window: series no_outlier=recode(returnquantile(return,0.025) and returnquantile(return,0.975), return, na) Press Enter. Crea

17、ting Dummy Variables Using recode: Example 6 (contd)18 The original series (return) and the new series are shown here. Original series No OutlierA Few Notes on Simple Dummy VariablesFor simple dummies, you dont need to use smpl or recode.You can create them simply by defining the logical expression

18、directly in the command window, as shown in the following examples. However, you may have to use smpl or recode for more complex cases. 19A few Notes on Simple Dummy Variables: Example 120Create a dummy equal to 1 if return=0, and 0 otherwise. Simple Dummies: Example 1Click on Dated workfile page. T

19、ype in the command window: series d1=return=0Press Enter. Original Series Dummy VariableA few Notes on Simple Dummy Variables: Example 221Create a dummy equal to 1 if return=0.1, and 0 otherwise. Simple Dummies: Example 2Click on Dated workfile page. Type in the command window: series d2=return=0.1P

20、ress Enter. Original Series Dummy VariableDate Dummy VariablesCreating Date DummiesDated dummies can be created by using recode and date or dateval.For more details on date functions, see tutorial on Date Functions.23FunctionDescriptiondateReturns the date associated with each observationdateval Ret

21、urns the date associated with a text representation of a dateyearReturns the year in which each observation beginsquarterReturns the quarter of the year in each observation beginsmonthReturns the month of the year in each observation beginsdayReturns the day of the month in each observations beginsw

22、eekdayReturns the day of the weekMain FunctionsCreating Date Dummies:Example 1 24Suppose you want to create a dummy variable equal to 1 for all dates after 1995/03/15 and 0 otherwise. Date Dummies: Example 1Click on the Dated workfile page. Now, type in the command window: series dumdate1=recode(dat

23、edateval(1995/3/15),1,0) Press Enter. Alternatively, without recode:Type in the command window: series dumdate1=datedateval(1995/3/15) Press Enter. Dummy VariableCreating Date Dummies:Example 2 25Create a dummy variable equal to 1 for all dates before April 1979 and after February 1994. Date Dummies

24、: Example 2Click on the Dated workfile page. Type in the command window: series dumdate2=recode(datedateval(1994m2),1,0) Press Enter (please type the command in one line). Alternatively, without recode:Type in the command window: series dumdate2=datedateval(1994m2) Press Enter (please type the comma

25、nd in one line). 26Creating Date Dummies: Example 2 (contd) Dummy VariableA graph of the new dummy variable is shown here. As you can see, it assumes a value of 1 prior to April 1979 and post February 1994. Creating Date Dummies:Example 4 27Dated dummies can also be created using year, month, day da

26、te functions.Create a dummy equal to 1 if the month is January or the day of the week is FridayDate Dummies: Example 4Click on the Dated workfile page. Now, type in the command window: series dumdate4=recode(month=1 or weekday=5,1,0) Press Enter. Alternatively, without recode:Type in the command win

27、dow: series dumdate4=month=1 or weekday=5Press Enter. Dummy VariableCreating Date Dummies:Example 528Create a dummy equal to 1 for all years after 1994 if the month is January or the day of the week is Friday.Date Dummies: Example 5Click on the Dated workfile page. Now, type in the command window: s

28、eries dumdate5=recode(year1994 and (month=1 or weekday=5),1,0) Press Enter. Alternatively, without recode:Type in the command window: series dumdate5=year1994 and (month=1 or weekday=5)Press Enter. Creating Date Dummies:Example 629Create a dummy variable equal to 1 for all months when there is a pre

29、sidential election. Date Dummies: Example 6Click on the Dated workfile page. Now, type in the command window: smpl all series dumpres=0 smpl if mod(year,4)=0 and month=11 series dumpres=1 smpl all Press Enter after each command line. Dummy VariableDummy Variables in Non-Dated WorkfilesDummies in Non

30、-dated Workfiles You can follow the methodology used in “Dated Dummies” to create dummies in non-dated workfiles.Simply use obsnum (instead of date) to create the dummy variables. 31Creating Dummies in Non-Dated Workfiles:Example 132In the Cross-Section page, create a dummy variable equal to 1 after

31、 the 5th observation, and 0 otherwise Dummies in non-Dated Workfiles: Example 1Click on the Cross-Section workfile page. Now, type in the command window: series dum1=recode(obsnum5,1,0)Press Enter. Dummy VariableAlternatively, without recode:Type in the command window: series dum1=obsnum5Press Enter

32、. Creating Dummies in Non-Dated Workfiles:Example 233In the Cross-Section page, create a dummy variable equal to 1 for all the observations between the 7th and 12th observationDummies in non-Dated Workfiles: Example 2Click on the Cross-Section workfile page. Now, type in the command window: series d

33、um2=recode(obsnum=7 and obsnum=7 and obsnumdateval(1994/12/2)Press Enter (type the command in one line). Alternatively:Select Quick Estimate Equation from the top menu bar.The Equation Estimation box opens up. Specify here your equation (as shown in the figure)Click OK. Dummies in Regressions: Examp

34、le 1 (contd)43The estimation output is shown here.As you can see EViews estimates the coefficient of the dummy variable directly without us having to create and save the date dummy first. *Note: see tutorial on Basic Estimation for details on regression analysis in EViews. Dummies in Regressions: Ex

35、ample 2Now suppose you would like to estimate a regression of return on volume1 and a dummy variable equal to 1 for all Januaries since 1994/12/2.44Dummies in Regressions: Example 2Click on the Dated workfile page. Type in the command window: equation eq2.ls return c volume1 (datedateval(1994/12/2) and month=1)Press Enter. Note that there are no spaces in the logical expression;month=1 is correctmonth = 1 is not correctDummies in Regressions: Example 3 45Now lets carry out a regression in the Cross_Section workfile page. Suppose we want to regress wage on exper, educ and

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論