Create a node programmatically then reference an existing node to that node?
As for the second part, you need to pass node ID or array of node IDs to node_load function first argument.

Your code should look like the following:

$node2 = node_load($nid); // pass integer node ID or array of integers 

$node2-&gt;field_reference['und'][0] = array(
  'target_id' =&gt; $node-&gt;nid, // pass integer node ID not node object
);

node_save($node2);

drupal_goto("node/{$node-&gt;nid}");