'How to multiply a child dummy variable with its respective ratios in python?
What I want to do is add the ratios in the 1st table based on the correct child in the 2nd table. So for example for the 1st observation I want to do 0.52 (1st child 16-17)+0.84 (2nd child 11-13)+0.78 (3rd child 0-3)=2.14 and create a new column for those values.
There are no observations with more than 1 child in any age range. The "Child_18-older_18" and "Pregnant" columns should be seen as someone with an age of 16-17 and 0-3 in the ratio table, respectively. With regards to the 2nd table, the entire dataframe consists of 4000 observations. These 5 observations were picked randomly
| Age | First_child_ratio | Second_child_ratio | Third_child_ratio | Fourth_child_ratio |
|---|---|---|---|---|
| 0-3 | 1.0 | 0.72 | 0.78 | 0.66 |
| 4-6 | 0.83 | 0.6 | 0.65 | 0.54 |
| 7-10 | 0.77 | 0.69 | 0.73 | 0.59 |
| 11-13 | 0.88 | 0.84 | 0.87 | 0.86 |
| 14-15 | 0.52 | 0.52 | 0.68 | 0.68 |
| 16-17 | 0.52 | 0.52 | 0.52 | 0.52 |
| Pregnant | Child_0-3 | Child_4-6 | Child_7-10 | Child_11-13 | Child_14-15 | Child_16-17 | Child_18-older_18 | No_Child |
|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
