How to create one entity and assign the same entity as field to new entity programatically
Once you have the ID of the new entities, it's as simple as:

$new_entity-&gt;field_foo[LANGUAGE_NONE][0]['target_id'] = $other_entity_id;
$new_entity-&gt;field_foo[LANGUAGE_NONE][1]['target_id'] = $yet_another_entity_id;


I've assumed the field type is Entity Reference, YMMV for other types.