Hello,
I'm a bit lost trying to figure out how to display zeros for factor variable percentages using the table and collect commands. I am using Stata 18.5 on Windows.
Below is a simplified example of what I am trying to accomplish.
the resulting output looks like this:
But I want it to look more like this manually-constructed example:
The table looks the way I want it to when only one level of a variable has a zero:
So far I have tried this, but it didn't change the resulting table:
This task is part of a larger block of code that uses loops to construct many tables, only some of which have zeros for some factor variable levels. Any potential solutions that require me to identify each cell/row with no observations and insert zeros manually would likely not be practical for my needs.
Any ideas are appreciated!
I'm a bit lost trying to figure out how to display zeros for factor variable percentages using the table and collect commands. I am using Stata 18.5 on Windows.
Below is a simplified example of what I am trying to accomplish.
Code:
sysuse nlsw88 table hours married collgrad // observse that there are zero observations of college graduates working 80 hours table collgrad if hours == 80, statistic(fvpercent married) // only shows percentages for non-college graduates with no row for college graduates at all
Code:
-------------------------------------- | Married | Single Married -------------------+------------------ College graduate | Not college grad | 50.00 50.00 Total | 50.00 50.00 --------------------------------------
Code:
-------------------------------------- | Married | Single Married -------------------+------------------ College graduate | Not college grad | 50.00 50.00 College grad | 0.00 0.00 Total | 50.00 50.00 --------------------------------------
The table looks the way I want it to when only one level of a variable has a zero:
Code:
. table collgrad if hours == 30, statistic(fvpercent married) -------------------------------------- | Married | Single Married -------------------+------------------ College graduate | Not college grad | 31.88 68.12 College grad | 0.00 100.00 Total | 28.21 71.79 --------------------------------------
Code:
sysuse nlsw88 table collgrad if hours == 80, statistic(fvpercent married) collect style cell result, empty(0) collect preview -------------------------------------- | Married | Single Married -------------------+------------------ College graduate | Not college grad | 50.00 50.00 Total | 50.00 50.00 --------------------------------------
This task is part of a larger block of code that uses loops to construct many tables, only some of which have zeros for some factor variable levels. Any potential solutions that require me to identify each cell/row with no observations and insert zeros manually would likely not be practical for my needs.
Any ideas are appreciated!
Comment