Dear all,

I am trying to create a new variable PTAextramother depending on the values of two other variables PTA_*_i and PTA_*_j (which could be equal to 0 or 1). The "*" corresponds to different numbers ranging from 1 to 955.

Therefore I tried this code:

This code works, but not for what I would like to do, i.e. :

- The first problem, is that I would like to exclude some PTA_*_i (and PTA_*_j) from the list (so for instance in the range 1/955, I would like to exclude : 2, 4 and 6), I don't know how to do that.

- the second problem is that I would like to generate a variable PTAextramother instead of PTAextramother`v' (which will take into account all PTA from 1 to 955). But I have a message error saying PTAextramother is already defined if I do it the way I want....

Could anyone help on those 2 points?

Many thanks,

I am trying to create a new variable PTAextramother depending on the values of two other variables PTA_*_i and PTA_*_j (which could be equal to 0 or 1). The "*" corresponds to different numbers ranging from 1 to 955.

Therefore I tried this code:

Code:

forval v=1/955 { capture confirm var PTA_`v'_j if _rc == 0 { gen PTAextramother`v' = 1 if PTA_`v'_i == 1 & PTA_`v'_j != 1 } }

- The first problem, is that I would like to exclude some PTA_*_i (and PTA_*_j) from the list (so for instance in the range 1/955, I would like to exclude : 2, 4 and 6), I don't know how to do that.

- the second problem is that I would like to generate a variable PTAextramother instead of PTAextramother`v' (which will take into account all PTA from 1 to 955). But I have a message error saying PTAextramother is already defined if I do it the way I want....

Could anyone help on those 2 points?

Many thanks,

## Comment