Creating indicator variables

It is easy to create indicator variables in gretl. Suppose that we want to create a dummy variable to indicate that a house is large. Large in this case means one that is larger than 2500 square feet.

1 series ld = (sqft>25)

2 discrete ld

3 print ld sqft —byobs

The first line generates a variable called ld that takes the value 1 if the condition in parentheses is satisfied. It will be zero otherwise. The next line declares the variable to be discrete. Often this is unnecessary. “Gretl uses a simple heuristic to judge whether a given variable should be treated as discrete, but you also have the option of explicitly marking a variable as discrete, in which case the heuristic check is bypassed.” (Cottrell and Lucchetti, 2011, p. 53) That is what we did here. Also from the Gretl Users Guide:

To mark a variable as discrete you have two options.

1. From the graphical interface, select “Variable, Edit Attributes” from the menu. A dialog box will appear and, if the variable seems suitable, you will see a tick box labeled “Treat this variable as discrete”. This dialog box [see Figure 7.1 below] can also be invoked via the context menu (right-click on a variable and choose Edit attributes) or by pressing the F2 key.

2. From the command-line interface, via the discrete command. The command takes one or more arguments, which can be either variables or list of variables.

So, the discrete declaration for ld in line 2 is not strictly necessary. Printing the indicator and square feet by observation reveals that the homes where sqft > 25 in fact are the same as those where ld =1.

ld

sqft

1

0

23.46

2

0

20.03

3

1

27.77

4

0

20.17

5

1

26.45

6

0

21.56

Leave a reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>