How to programmatically create an entity and fill in entity reference fields
The column name for a field isn't always value; in the case of entity references it's target_id if I remember rightly. 

Try this:

$entity = entity_create('mytype', $values);
$entity-&gt;field_ref = array('und' =&gt; array(0 =&gt; array('target_id' =&gt; "2")));