Apologies in advance for a basic question, but I’m fairly new to Stata and have been stuck on this for a little while now!
I currently have a table with the first column being case IDs, and the following columns being matched control IDs. Finally there’s an index date which corresponds to all IDs in that row. I need to reshape my data so that I have all case and control IDs in one column, with the index date preserved. (Additionally I need a column which flags any IDs from the ‘CaseA’ column as 1 – however this isn’t the part I’m struggling with.)
CaseA | ControlB1 | ControlB2 | ControlB3 | ControlB4 | IndexDate |
---|---|---|---|---|---|
ID_1 | ID_2 | ID_3 | ID_4 | ID_5 | 1/1/01 |
ID_6 | ID_7 | ID_8 | ID_9 | ID_10 | 1/2/01 |
ID_11 | ID_12 | ID_13 | ID_14 | ID_15 | 1/5/01 |
IDs | IndexDate | Case/control |
---|---|---|
ID_1 | 1/1/01 | 1 |
ID_2 | 1/1/01 | 0 |
ID_3 | 1/1/01 | 0 |
ID_4 | 1/1/01 | 0 |
ID_5 | 1/1/01 | 0 |
ID_6 | 1/2/01 | 1 |
ID_7 | 1/2/01 | 0 |
… and so on.
I have looked into transpose and have been trying approaches with reshape:
reshape long CaseA ControlB*, i(IndexDate)
But I don’t think the data is quite in the right format for this.
Any advice greatly appreciated!
Thank you.
Emma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.