I was able to get the non-imputated data in a very nice format for the first table (sex) in the spreadsheet, but I cannot add the second table with row variable "age".
My command is like follows:
Code:
*Tables independent variables in excel *Variable Sex local RowVar = "S1" local ColVar = "av" mi xeq 0: tabulate `RowVar' if !missing(`ColVar'), matcell(rowtotals) mi xeq 0: tabulate `RowVar' `ColVar', matcell(cellcounts) local RowCount = r(r) local ColCount = r(c) local RowValueLabel : value label `RowVar' levelsof `RowVar', local(RowLevels) putexcel set table.xlsx, sheet(av) modify forvalues row = 1/`RowCount' { local RowValueLabelNum = word("`RowLevels'", `row') local CellContents : label `RowValueLabel' `RowValueLabelNum' local Cell = char(64 + 1) + string(`row'+1) putexcel `Cell' = "`CellContents'", right forvalues col = 1/`ColCount' { local cellcount = cellcounts[`row',`col'] local cellpercent = string(100*`cellcount'/rowtotals[`row',1],"%9.1f") local CellContents = "`cellcount' (`cellpercent'%)" local Cell = char(64 + `col' + 1) + string(`row' + 1) putexcel `Cell' = "`CellContents'", right } } local RowVar = "age" local ColVar = "av" mi xeq 0: tabulate `RowVar' if !missing(`ColVar'), matcell(rowtotals) mi xeq 0: tabulate `RowVar' `ColVar', matcell(cellcounts) local RowCount = r(r) local ColCount = r(c) *Variable Age local RowValueLabel : value label `RowVar' levelsof `RowVar', local(RowLevels) putexcel set table.xlsx, sheet(av) modify forvalues row = 1/`RowCount' { local RowValueLabelNum = word("`RowLevels'", `row') local CellContents : label `RowValueLabel' `RowValueLabelNum' local Cell = char(64 + 1) + string(`row'+1) putexcel `Cell' = "`CellContents'", right forvalues col = 1/`ColCount' { local cellcount = cellcounts[`row',`col'] local cellpercent = string(100*`cellcount'/rowtotals[`row',1],"%9.1f") local CellContents = "`cellcount' (`cellpercent'%)" local Cell = char(64 + `col' + 1) + string(`row' + 1) putexcel `Cell' = "`CellContents'", right } }
The error message after the last line of command is as follows:
0 invalid name
r(198);
Could you please give me some advice on how to solve this problem?
0 Response to Putexcel: Cannot add tables in excel on same spreadsheet
Post a Comment