I have an individual level cross-sectional dataset. The observations are individuals belonging to a family which in turn is part of a household. The household can have one or multiple families.

My goal is to obtain the gender ratio of weekly housework hours by dividing the man's hours of housework with the partner's ones.

There is a variable called v31 that is equal to 1 when the individual is the principal member of the family (the woman) and equal to 2 when the individual is the husband. I also have a variable containing the household ID (v4) and another variable that tells me the progressive number of the family within the household (v32), which is equal to 1 if it is the first family of the household, 2 if it is the second... .

An example of the code:
Code:
 
 clear  input obs v4 v32 v31 v850 1 1 1 1 27 2 1 1 2 12 3 2 1 2 8 4 2 1 1 41 5 3 1 2 0 6 4 1 1 29 7 4 1 2 11 8 4 2 1 37 9 4 2 2 1 end  list
By looking at the data example above, my goal would be to have a new variable called domwork_ratio which for example for line 1 and line 2 would have have the ratio of housework hours of the male partner and female partner, which would be 12/27. It will have the same value for both observations since they belong to the same family (v32) (and to the same household (v4)).

The issue is that I do not know how to tell stata to do the ratio so that each husband's housework hours are divided by his partner's ones.

I have tried using the command:
Code:
 
 bysort v4 v32 v16: gen domwork_ratio = cond(v4 != v4[_n-1],999999,v850_tot[_n-1]/v850_tot)
However it creates the variable domwork_ratio with 999999 as the only value.

Any help would be much appreciated,
Vincenzo