Hi everyone,
I would like to assign the value/s of one variable to a different variable for a different ID.
For example, I would like the newly created variable test to equal the sum of variable1 values for IDs #4 and #22 on ID #13.
Something like:
gen test=0
replace test= variable1[id==4]+variable1[id==22] if id==13
A workaround would be to create new variables where values for all records for that variable is the value/s of interest (example below) but I was hoping there might be a more simple approach.
gen test = 0
gen variable2 = variable1 if id==4
egen variable3=max(variable2)
gen variable4 = variable1 if id==22
egen variable5 = max(variable4)
replace test = variable3+variable5 if id==13
Thanks very much!
I would like to assign the value/s of one variable to a different variable for a different ID.
For example, I would like the newly created variable test to equal the sum of variable1 values for IDs #4 and #22 on ID #13.
Something like:
gen test=0
replace test= variable1[id==4]+variable1[id==22] if id==13
A workaround would be to create new variables where values for all records for that variable is the value/s of interest (example below) but I was hoping there might be a more simple approach.
gen test = 0
gen variable2 = variable1 if id==4
egen variable3=max(variable2)
gen variable4 = variable1 if id==22
egen variable5 = max(variable4)
replace test = variable3+variable5 if id==13
Thanks very much!
Comment