Hi Statalist community,
I am trying to use the mkmat command to create a matrix with the desired variables and then I want to export to an Excel spreadsheet. Below is sample code that illustrates my situation. I can't seem to add the variable names so that it appears in the excel spreadsheet. I am new to creating my own matrices and assistances would greatly be appreciated. Thanks in advance.
I am trying to use the mkmat command to create a matrix with the desired variables and then I want to export to an Excel spreadsheet. Below is sample code that illustrates my situation. I can't seem to add the variable names so that it appears in the excel spreadsheet. I am new to creating my own matrices and assistances would greatly be appreciated. Thanks in advance.
Code:
*pull in sample data use https://www.stata-press.com/data/r18/nhanes2l, clear *run regression logit highbp bmi age *estimate marginal effects by age margins, at(age = (20 (1) 60)) nose *put results in a matrix mat mat_results = nullmat(mat_results), r(b)' clear *Call up matrix svmat mat_results, names(MM) *Create an age variable gen age = _n + 17 order age, first *Grab the age variable and marginal effects variable and put it in a matrix called matrix_group1 *This is my attempt at adding variable names to the matrix. I am stuck here. mkmat age MM1, mat(matrix_group1) rownames(age) *Tell Stata which excel spreadsheet to use putexcel set practice.xlsx, modify *Tell Stata to put the matrix in cell A2 putexcel A2= matrix(matrix_group1), rownames
Comment