I need help with some coding! It would be great if some of you could help me...
I wanted to ask if it's possible to create a loop in order to sequentially create several new variables (names ranging from A to Z, for example) which are equal to a group of observations which is derived from a combination of specific values from the other variables (for example, if you have two other variables which are called 'woman' (1 if yes, 0 if no) and 'rent' ('high','medium' and 'low'), what I wanted to ask is if it is possible to form a loop to create variables which are equal to every combination of values from these groups of observations from the other variables.
Here is an example, but without a loop:
a<-data[data$woman==1 & data$rent=="high",]
b<-data[data$woman==1 & data$rent=="medium",]
If there were to be more variables other than 'woman' and 'rent', how could this be coded?
I'm really thankful if someone has the time to help me!