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
Asked
Active
Viewed 340 times
1
-
An example of what the data is like is the following table: Induviduo - Salary 1-800 2--500 3 4--905 5--5050 6--850 7- 8--410 9--1100 10--7400 – Albert Aedo Pereira Aug 12 '18 at 20:17
-
Did the code I wrote solved your problem? – Henrique Andrade Aug 16 '18 at 21:47
2 Answers
0
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)

Henrique Andrade
- 71
- 6
0
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

atecon
- 21
- 4