GRETL - missing command to create dummy variables in GRETL

363 views Asked by At

GRETL - How do I create a dummy variable with a column that contains the salary of an individual, being 1 when the salary exists and 0 when salary is empty using the missing command in GRETL

2

There are 2 answers

0
Henrique Andrade On

You can use the "ok" function:

##### Creating Salary series #####
nulldata 10

series Salary = NA
matrix m = {800, 500, NA, 905, 5050, 850, NA, 410, 1100, 7400}

loop i = 1..10 
    Salary[i] = m[i]
endloop
##################################

series dummy = ok(Salary)
0
atecon On

This is a shorter way of doing what you need, and it will be much faster when working with large data as no looping is involved:

nulldata 3
series salary = {800, 500, NA}
series salary_dummy = NA

# if salary is _not_missing_ return '1', else '0'
series salary_dummy = (ok(salary)) ? 1 : 0
print salary salary_dummy -o

This returns:

        salary     salary_dummy
1          800            1
2          500            1
3                         0