I am trying to create several descriptive tables, using putexcel. I am struggling to get a working matrix of column names to put into the putexcel command.
First I generate the table:
Code:
 tab x year [aweight=weight] , matcell(xmatrix)
This code will eventually be in a loop, over several different x variables. The data includes the years 2000-2018, but any given x will have a subset of those years.
This means that when I try to assign a local containing the years to be my column names
Code:
matrix colnames xmatrix = `year'
I get an error because colnames has 19 values but there are fewer in the matrix because there were no observations of x in some years.

I assume it should be relatively straightforward to get the column labels, but I am struggling and would appreciate any guidance