Create new child field collection programmatically
You try the code:

&lt;?php 
use Drupal\field_collection\Entity\FieldCollectionItem;
use Drupal\node\Entity\Node;

[.....]

  $node = Node::load(7);
  $field_collection_item = FieldCollectionItem::create(
    [
      'field_name' =&gt; 'field_test_student_info',
    ]
  );

  $field_collection_item-&gt;set('field_student_name', 'Student Name');

  $field_mark_collection = FieldCollectionItem::create(['field_name' =&gt; 'field_marks']);
  $field_mark_collection-&gt;set('field_english_marks', '1231');
  $field_mark_collection-&gt;set('field_history_marks', '123');
  $field_collection_item-&gt;field_marks[] = ['field_collection_item' =&gt; $field_mark_collection];
  $node-&gt;field_test_student_info = ['field_collection_item' =&gt; $field_collection_item];
  $field_collection_item-&gt;setHostEntity($node);
  $node-&gt;save();


You need create new collection field  FieldCollectionItem::create(['field_name' =&gt; 'field_marks']) 

You can set value to the file child in field parent collection, it is same you when set value field collection in node, here you dont's need set setHostEntity, it will understand is the field_collection_item

As the code above I also checked it, and it worked.

You can refer to it here 

Goodluck