User’s Guide : EViews Fundamentals : Basic Data Handling : Sample Objects
Sample Objects
Creating a Sample Object
Using a Sample Object
As you have seen, it is possible to develop quite elaborate selection rules for the workfile sample. However, it can become quite cumbersome and time-consuming to re-enter these rules if you change samples frequently. Fortunately, EViews provides you with a method of saving sample information in an object which can then be referred to by name. If you work with many well-defined subsets of your data, you will soon find sample objects to be indispensable.
Creating a Sample Object
To create a sample object, select Object/New Object… from the main menu or the workfile toolbar. When the New Object dialog appears, select Sample and, optionally provide a name. If you do not provide a name, EViews will automatically assign one for you (sample objects may not be untitled). Click on OK and EViews will open the sample object specification dialog:
Here is a partially filled-in sample object dialog for SMPL1. Notice that while this dialog looks very similar to the one we described above for setting the sample, there are minor cosmetic differences: the name of the sample object appears in the title bar, and there is a check box for setting the workfile sample equal to this sample object.
These cosmetic differences reflect the two distinct purposes of the dialog: (1) to define the sample object, and (2) to set the workfile sample. Since EViews separates the act of defining the sample object from the act of setting the workfile sample, you can define the object without changing the workfile sample, and vice versa.
To define the sample object, you should fill out this dialog as described before and click on OK. The sample object now appears in the workfile directory with a double-arrow icon.
To declare a sample object using a command, simply issue the sample declaration, followed by the name to be given to the sample object, and then the sample string:
sample mysample 1955m1 1958m12 if rc>3.6
EViews will create the sample object MYSAMPLE which will use observations between 1955:01 and 1958:12, where the value of the RC series is greater than 3.6.
Using a Sample Object
You may use a previously defined sample object directly to set the workfile sample. Simply open a sample object by double clicking on the name or icon. This will reopen the sample dialog. If you wish to change the sample object, you may edit the sample specification; otherwise, simply click the Set workfile sample check box and click on OK.
Or, you may set the workfile sample using the sample object, by entering the smpl command, followed by the sample object name. For example, the command:
smpl mysample
will set the workfile sample according to the rules contained in the sample object MYSAMPLE.
For many purposes, you may also use a named sample object as though it were an ordinary EViews series containing the values 1 and 0, for observations that are and are not included, respectively. Thus, if SMP2 is a named sample object, you may use it as though it were a series in any EViews expressions (see “Series Expressions”). For example:
y1*(smp2=0) + 3*y2*(smp2=1)
is a valid EViews expression, evaluating to the value of 3*Y2 if an observation is in SMP2, and Y1, otherwise.
You may also, for example, create a new series that is equal to a sample object, and then examine the values of the series to see which observations do and do not satisfy the sample criterion.
Additionally, one important consequence of this treatment of sample objects is that you may use sample objects in the construction of other sample objects. For example, if you create a sample object FEMALE containing observations for individuals who are females,
sample female @all if gender="female"
and a second sample object HIGHINC if INCOME is greater than 25000:
sample highinc @all if income>25000
You may set the sample to observations where individuals are low income females using:
smpl @all if female and not highinc
where we use the NOT keyword to take the complement of the observations in HIGHINC. To create a sample object HIGHFEMALE using this sample, use the command:
sample highfemale @all if female and not highinc
Alternatively, we could have used the equivalent expression
sample highfemale @all if female and highinc=0
More generally, we may use any expression involving sample objects and the keywords “AND”, “OR”, and “NOT”, as in
smpl 1950 1980 if female or not highinc
which sets the sample to those observations from 1950 to 1980 that are also in the sample FEMALE, but not in the sample HIGHINC.