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)
Code: Select all
series dummy2 = @recode(X>=0.5 and X<=1, 1, 0)
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)
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)
Code: Select all
series dummy5 = @recode(@date<@dateval("1980") or @date>@dateval("1990"), 1, 0)
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)
Code: Select all
series dummy7 = @recode(@month=1, 1, 0)
Code: Select all
series dummy8 = @recode(@weekday=3, 1, 0)
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")

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)
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)
Code: Select all
@expand(@obsid)
