Hi

(Apologies for the clumsy title, I couldn't think of a better description)

I am working with a dataset where each row consists of a datapoint from a systematic review - each data point has the unique identifier dpid and is clustered within a study (indicated by studyid). I also have the variables exposurecomb and outcome.

The first datapoint for each unique combination of dpid, exposurecomb, and outcome has been given a numerical quality rating for different criteria, which is recorded in the 5 variables ending in "_num".

For the datapoints missing quality ratings, I want to assign the quality ratings (i.e. the values of the _num variables) from the corresponding datapoint with the same studyid, exposurecomb, and outcome which does have data for the quality rating variables.

e.g. in the example below, the missing data in rows 2-4 should be replaced by the values 0 1 1 0 1 as recorded in row 1, and the missing data in rows 6-8 should be replaced by the values 0 1 1 1 1 as recorded in row 5.

I have been trying to find a way of doing this using _n or using reshape based on studyid/exposurecomb/outcome, but not having any success - I would be very grateful for any suggestions.

Many thanks


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str8 dpid str6 covid str22 exposurecomb str127 outcome float(rep_num ascexp_num ascout_num resp_num selco_num)
"10010/1" "10010" "SMI + HL"               "PTSD"                                          0 1 1 0 1
"10010/2" "10010" "SMI + HL"               "PTSD"                                          . . . . .
"10010/3" "10010" "SMI + HL"               "PTSD"                                          . . . . .
"10010/4" "10010" "SMI + HL"               "PTSD"                                          . . . . .
"10010/5" "10010" "SMI + SU"               "PTSD"                                          0 1 1 1 1
"10010/6" "10010" "SMI + SU"               "PTSD"                                          . . . . .
"10010/7" "10010" "SMI + SU"               "PTSD"                                          . . . . .
"10010/8" "10010" "SMI + SU"               "PTSD"                                          . . . . .
"10043/1" "10043" "SU + HL"                "Non-fatal overdose in previous six months"     1 1 1 0 1
"10043/2" "10043" "SU + SW"                "Non-fatal overdose in previous six months"     1 0 1 0 1
"10048/1" "10048" "SU + PR"                "Recent cutaneous infections"          1 1 1 0 1
"10048/2" "10048" "SU + HL"                "Recent cutaneous infections"          1 1 1 0 1
"10048/3" "10048" "SU + SW"                "Recent cutaneous infections"         1 1 1 0 1
"10048/4" "10048" "SU + PR"                "Recent cutaneous infections"          . . . . .
"10048/5" "10048" "SU + HL"                "Recent cutaneous  infections"          . . . . .
"10048/6" "10048" "SU + SW"                "Recent cutaneous infections"         . . . . .
"10075/1" "10075" "SU + HL"                "HIV infection"                                 1 0 1 0 1
"10075/2" "10075" "SU + SW"                "HIV infection"                                 1 0 1 0 1
"10075/3" "10075" "SU + SW"                "HIV infection"                                 . . . .