Gretl- How to create a dummy variable that says the individual has a small child

1.3k views Asked by At

I have a variable that is the age of the last child and I have to create a dummy for individuals who have children under 6 years of age, we also have some individuals who have empty values, or have had no children.

example of variable: 1 - 10 2 - 5 3 - 7 4 - 30 5 - 6 - 25 7 - 3 8-15 9 - 10 - 33

1

There are 1 answers

0
Henrique Andrade On BEST ANSWER

If I understood correctly, you want to create a dummy using two conditions:

dummy = 1 if:
(condition 1) the age is less than 6
(condition 2) the age is available (or different from NA)

To achieve that using Gretl you can use:

##### Creating "age of the last child" series #####
nulldata 10

series age_of_the_last_child = NA
matrix m = {10, 5, 7, 30, NA, 25, 3, 15, NA, 33}

loop i = 1..10 --quiet
    age_of_the_last_child[i] = m[i]
endloop
###################################################

series dummy = (age_of_the_last_child < 6) ? 1 : 0
series dummy = misszero(dummy)

Or, if you want a more compact way:

series dummy = misszero((age_of_the_last_child < 6) ? 1 : 0)