Simple Dummies

The easiest way to create a dummy variable is with the @recode function. @recode lets you specify a logical test, and the values a variable should take if that test is true, or if it is false:

- Code: Select all
`series dummy1 = @recode(X>0.5, 1, 0)`

This will create a series called dummy1 that is equal to 1 whenever the series X is greater than 0.5, and equal to 0 otherwise. You can use the AND or OR operators to make more complicated logical tests:

- Code: Select all
`series dummy2 = @recode(X>=0.5 and X<=1, 1, 0)`

will create a dummy that is equal to 1 whenever X is between 0.5 and less than 1.

Date Dummies

You can use @recode to create dummy variables based upon dates too. In dated workfiles there are a collection of keywords you can use to refer to the date of each observation. The first of these is the @date keyword that returns the date number associated with each observation's date. You can couple this with the @dateval command to create a date number based upon the text representation of a date, in order to create dummy variables based upon dates:

- Code: Select all
`series dummy3 = @recode(@date>@dateval("2010/03/02"), 1, 0)`

This will create a dummy variable, dummy3 that is equal to 1 for all dates after 2010/03/02.

You can extend this with ANDs and ORs too:

- Code: Select all
`series dummy4 = @recode(@date>@dateval("2010/03/02") and @date<@dateval("2010/06/02"), 1, 0)`

creates a dummy variable equal to 1 between 2010/03/02 and 2010/06/02.

- Code: Select all
`series dummy5 = @recode(@date<@dateval("1980") or @date>@dateval("1990"), 1, 0)`

creates a dummy equal to 1 for all dates before 1980 or after 1990.

You can use other date keywords to create dummies too. The @year specifies the year part of each observations. Thus:

- Code: Select all
`series dummy6 = @recode(@year>1990, 1, 0)`

creates a dummy equal to 1 for all observations which lie after 1990.

- Code: Select all
`series dummy7 = @recode(@month=1, 1, 0)`

creates a dummy equal to 1 for all observations in January.

- Code: Select all
`series dummy8 = @recode(@weekday=3, 1, 0)`

creates a dummy equal to 1 for all observations on a Wednesday.

Dummies in Equations

Note you do not have to actually create the dummy series inside the workfile to use dummy variables in an equation, rather you can enter the dummy expression directly in the equation specification, either via command:

- Code: Select all
`equation eq1.ls Y C X @date>@dateval("1990")`

or via dialog:

Note that in both cases you should not have spaces in the logical expression. @year>1990 is fine, but @year > 1990 is not.

Categorical Dummies

If you have a categorical variable and wish to create dummy variables for each unique values in that variable, you can do so easily using the @expand command. For example, say you have a variable called "Sex" that is either "M" or "F", you could create an equation with the following specification:

which would give the following output:

Note that by default the @expand keyword will create a full set of dummies, thus you should not include a constant in your equation (since you'll create a singular matrix problem).

Alternatively, @expand lets you drop certain values from the expansion to avoid the singularity problem. You can use @dropfirst or @droplast to drop the first or the last categorisation. Thus:

- Code: Select all
`Y C X @expand(sex, @dropfirst)`

Would regress Y on a constant, X and SEX=M, and not SEX=F.

Fixed Effect Dummies

Fixed effects in panel estimation can be thought of as having a dummy variable for each cross-section. In most cases you don't need to worry about that, since EViews will add the fixed effects for you as an option during estimation. But sometimes you might want to create the dummy variables yourself. To do so is relatively simple, using @expand. Simply include this:

- Code: Select all
`@expand(@crossid)`

in your specification to include cross-section fixed effects. For period fixed effects, simply include:

- Code: Select all
`@expand(@obsid)`

Remember to be careful of the dummy variable trap. You might want to drop one of the dummies, as outlined above.