I have a dataset reporting the id of the households (varname: nquest), then to each component is given a number (varname: nord) and it is also reported the gender (sex=1 if male and sex=2 if females)
i would like to create two variables, one reporting the number of males per households and another the number of females per households and have a result like this one:
| nquest | nord | sex |
| 100 | 1 | 1 |
| 100 | 2 | 1 |
| 100 | 3 | 2 |
| 101 | 1 | 1 |
| 102 | 1 | 2 |
| 102 | 2 | 1 |
| 103 | 1 | 2 |
| 103 | 2 | 2 |
| 103 | 3 | 1 |
i would like to create two variables, one reporting the number of males per households and another the number of females per households and have a result like this one:
| nquest | nord | sex | males | females |
| 100 | 1 | 1 | 2 | 1 |
| 100 | 2 | 1 | 2 | 1 |
| 100 | 3 | 2 | 2 | 1 |
| 101 | 1 | 1 | 1 | 0 |
| 102 | 1 | 2 | 1 | 1 |
| 102 | 2 | 1 | 1 | 1 |
| 103 | 1 | 2 | 0 | 3 |
| 103 | 2 | 2 | 0 | 3 |
| 103 | 3 | 2 | 0 | 3 |

Comment