Relation between the weak itinerant magnetism in A2Ni7 compounds (A  =  Y, La) and their stacked crystal structures