Hello,
In the past, I have been able to change the style of the cell (line 43 in the code below), to change the numbering format and add a % sign next to the numbers in those cells. However, I have noticed that as of recent, this no longer works.
The following code:
... results in the following table:
In above table, in the cells of the %/(SD) column of the Race variable, the numbers are not formatted as they should be by line 43 of the code above, which is the following line of code below:
Can you advise as to what might be the reason? Is the code syntax incorrect (even though I do not get an error)?
Thank you for your support!
In the past, I have been able to change the style of the cell (line 43 in the code below), to change the numbering format and add a % sign next to the numbers in those cells. However, I have noticed that as of recent, this no longer works.
The following code:
Code:
clear
webuse nhanes2l
tab highbp
collect clear
collect layout, clear
* Obtain an initial table with necessary statistics
collect: table ///
(var) ///
(highbp), ///
statistic(mean age) ///
statistic(sd age) ///
statistic(fvfrequency race) ///
statistic(fvpercent race)
* Recode the levels of the result dimension to allow combined placement of the statistic of interest later in the shared cells in the final table
collect recode result ///
fvfrequency = variable_measure ///
fvpercent = variable_spread ///
mean = variable_measure ///
sd = variable_spread //
*Add labels to the mentioned combined levels for better table readability
collect label levels result variable_measure "Count / Mean" variable_spread "% / (SD)"
*Changing cell styles
* continuous variables
collect style cell ///
var[age]#result[variable_measure] ///
, nformat(%4.0fc)
collect style cell ///
var[age]#result[variable_spread] ///
, nformat(%4.1fc) sformat("(%s)")
* categorical variables
collect style cell ///
var[race]#result[variable_measure] ///
, nformat(%4.0fc)
collect style cell ///
var[race]#result[variable_spread] ///
, nformat(%4.0fc) sformat("%s%%") // THIS IS THE COMMAND THAT DOES NOT APPLY
*Create the final table
collect layout ///
(var) ///
(highbp#result[variable_measure variable_spread])
Code:
Collection: Table
Rows: var
Columns: highbp#result[variable_measure variable_spread]
Table 1: 4 x 6
------------------------------------------------------------------------------------------
| High blood pressure
| 0 1 Total
| Count / Mean % / (SD) Count / Mean % / (SD) Count / Mean % / (SD)
------------+-----------------------------------------------------------------------------
Age (years) | 42 (16.8) 55 (14.9) 48 (17.2)
Race=White | 5317 88.98745 3748 85.64899 9065 87.57608
Race=Black | 545 9.121339 541 12.36289 1086 10.49174
Race=Other | 113 1.891213 87 1.988117 200 1.93218
------------------------------------------------------------------------------------------
In above table, in the cells of the %/(SD) column of the Race variable, the numbers are not formatted as they should be by line 43 of the code above, which is the following line of code below:
Code:
collect style cell ///
var[race]#result[variable_spread] ///
, nformat(%4.0fc) sformat("%s%%")
Thank you for your support!

Comment