You can lookup DocumentIDs and put them into $REF. The trick is not using any intermediaries or holding places (i.e. temporary variables, environmental variables, view columns). You have to set it directly equal to the results of @DbLookup. You are right, $REF is a special data type, called 'Response Reference List'.
Let's say that you want to reassign the $REF field of a series of response documents, based on some key that the new parents share with the documents that will be their new children (let's call this field 'keyValue' which exists in both potential parent and response). Create a view, call it 'Parents by keyValue'. The selection formula should select only the potential parents, and the first sorted column should be the keyValue field (you don't need to add any other columns). Now run the following macro on all the documents in this view:
FIELD parentID := @DocumentUniqueID;
This parentID field now holds the parent's DocumentID and is the special data type 'Response Reference List'. Note: do not create a parentID field in your form; this field is created on-the-fly by the macro.
Now create a view called 'Responses', which selects only the potential children (make sure the View Attribute 'No Response Hierarchy' is set). Run the following macro on all of the documents in this view:
FIELD $REF := @DbLookup("":"NoCache"; ""; "Parents by keyValue"; keyValue; "parentID");
You've successfully reset the $REF field. If there is no keyValue, and there is no way to set one effectively, then you can reset the $REF field by cutting a potential response, highlighting the new parent and pasting it 'onto' the new parent.