问题描述:

I have a Stata dataset containing variables: `A1`

, `B1`

, `A2`

, `B2`

, `A3`

, `B3`

,..., `A15`

, `B15`

. All variables with `A`

are gender and those with `B`

are the corresponding ages.

How can I combine all variables into just two variables, `A`

and `B`

? So A would be `A1+A2+A3`

, ... ,`A15`

and similarly for `B`

?

The obvious answer seems to be

```
generate A = A1+A2+A3 ...
generate B = B1+B2+B3 ...
```

or less painfully,

```
egen A = rowtotal(A*)
egen B = rowtotal(B*)
```

assuming you have no other variables whose names begin with A or B. The obviousness of these answers makes me think I've not correctly understood what you hope to accomplish. Perhaps you should reveiew the following and pose your problem in the manner suggested.

http://stackoverflow.com/help/mcve