As part of a matching exercise, I am trying to bring in information from one observation into a different observation, within the same dataset. I am using the SSC command -vlookup-, which seems to offer exactly what I need, but encountering an unexpected error. I'm using Stata/SE 14.1 on Windows 10.
I start with the first three columns of this dataset:
And I wish to generate a fourth column d_date_match that "looks up" match_id from the id column, and takes the value of d_date from the corresponding observation. Note that in my full dataset, as in this example, the values of id are unique (that is: <isid id> runs without error). So the desired output is this:
Searching Statalist for advice on how to do this I found that Nick Cox had previously recommended the user-written command vlookup (https://www.statalist.org/forums/for...mmand-in-stata). So I installed that, and ran:
But alas, I got this error:
Which is very confusing since the two parts of that error message contradict each other. But also, the only field that needs to be unique is the key in the key-value pair: -id- in my example (and it is).
Note that another confusing error message from vlookup has been reported before with no response: https://www.statalist.org/forums/for...ssc-user-kcrow. Given the lack of response to that post, I fear this command is not well supported. So a workaround would be welcome as well.
Many thanks!
I start with the first three columns of this dataset:
Code:
clear input id matchid d_date 102 351 21246 232 283 . 280 426 21244 283 232 21266 351 102 . 426 280 . end
Code:
clear input id matchid d_date d_date_match 102 351 21246 . 232 283 . 21266 280 426 21244 . 283 232 21266 . 351 102 . 21246 426 280 . 21244 end
Code:
vlookup matchid, gen(d_date_match) key(id) value(d_date)
Code:
d_date is unique within id; there are multiple observations with different d_date within id.
Note that another confusing error message from vlookup has been reported before with no response: https://www.statalist.org/forums/for...ssc-user-kcrow. Given the lack of response to that post, I fear this command is not well supported. So a workaround would be welcome as well.
Many thanks!
Comment