Just a few thoughts after looking at some records today …….
Ecclefechan is where your William McDonald is living in the census, and on one, he records himself born there. Ecclefechan is 2 miles from Hoddom, and (as far as I understand) the parish church was in Ecclefechan.
Hoddom parish records seem rather thin and there are no kirk sessions available. However the name McDonald seems not particularly common in this part of Scotland.
There are a couple of McDonald families in Ecclefechan that might be related, and you may wish to explore further.
The family that took my interest was that of
James McDonald and Ann Jamieson (children baptised between 1819-1829 with similar names to William’s family.)
James obviously died before 1841 census, but his widow Ann can be found in the census.
1841 census for Ann McDonald Ecclefechan , carter (mis-transcribed as McDonnell)
https://www.freecen.org.uk/search_records/5902e700e9379091b1d098a7/anne-mcdonnell-1841-dumfriesshire-hoddam-1786-?locale=en1851 census Ann McDonald Ecclefechan , carter
Ann McDonald Head Widow 72 F Carrier Born England
Henry McDonald Son Unmarried 17 M Ag. Lab. Born Dumfries, Hoddom
James McDonald Son 6 M Scholar Born Dumfries, Hoddom
Mary Jamieson Mother Widow 92 F Pauper Born England
1861 census – living next door to your William McDonald
Anne McDonald Ecclefechan High Street, Pauper Carrier, with grandchildren
https://www.freecen.org.uk/search_records/5a148cd6f4040b9d6e87725f/anne-mcdonald-1861-dumfriesshire-hoddam-1781-?locale=enI wonder -
Did your William McDonald take over Anne’s carting / carrying work by 1871 as she was too old? Could she have been his sister-in-law?Anne (Jamieson) McDonald died in 1874 Hoddom (age 96)