Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Question about displaying empty cells when using collect

    I am using collect to create a simple table of proportions using a stacked layout where confidence intervals (CIs) are placed on a separate row below the proportions. I'd like to retain the "95% CI" row when the proportion is zero and include a placeholder like "NA" for the CIs. However, the default behavior shown in Example 1 is for Stata to drop the unused CI row.

    For the horizontal layout in Example 2 I used collect style cell, empty(NA) to replace the missing CIs with NA. Unfortunately, this option has no effect on the stacked layout, nor does collect style showempty on. I'd appreciate any advice on how to retain the CI row and insert a placeholder like "NA" for the stacked layout in Example 1.

    I am using StataNow/MP 19.5 for Windows.


    Code:
    clear all
    
    set obs 50
    
    * Binary Dependent Variable
    gen depvar = round(runiform())
    
    * 5-Category Independent Variable
    gen indvar = round(runiform() * 4) + 1
    
    * Replace Dependent Variable = 0 for 1st Category of Independent Variable
    replace depvar = 0 if indvar == 1
    
    * Collect Results from Proportion    
    collect clear
    
    collect: prop depvar, over(indvar)
    
    * Empty Cells as NA
    collect style cell, empty("NA")
    collect style showempty on
    
    * Example 1: No Confidence Interval Row Displayed for 0 Proportion
    collect layout (colname#result[_r_b _r_ci])
    
    * Example 2: Confidence Intervals Showing NA as Desired
    collect layout (colname) (result[_r_b _r_ci])

  • #2
    collect style showempty controls the visibility of coefficients for empty cells of factor-variable interactions. It has nothing to do with empty cells in the table's layout. Thus collect style showmepty on has no effect in your example.

    In Example 1, some of the CI rows are entirely unmatched among the items in the collection, so the layout code does not make any room for it in the table.

    In Example 2, some of the cells in the CI column match with items in the collection, so the layout code make room for the column. After the layout code is finished, the collect style cell, empty("NA") property takes effect.

    You are going to have to add a CI bound result for the cases when the SE is 0, for the layout in Example 1 to get empty cells filled with "NA".

    For example, the following code loops over the column names of e(b), looks for zero-valued SE estimates, and assigns a string "NA" to result _r_ub for that column name if found.
    Code:
    local colna : colna e(b)
    foreach x of local colna {
        if _r_se[`x'] == 0 {
            collect get _r_ub="NA", tags(colname[`x'])
        }
    }
    I will look into getting the collect style cell, empty("NA") property respected when the layout code is matching items to the table cells, but in this case it would be better to aim this property at a specific result, like
    Code:
    collect style cell result[_r_ub], empty("NA")

    Comment


    • #3
      Jeff, I appreciate the quick response and your efforts to help Stata users with the new collect commands. I was working on something close to what you suggested but couldn't quite get it. Thanks again for the help.

      Comment

      Working...
      X