Announcement

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

  • Including factor variable using dtable and collect with multiple panels

    I am trying to make a table of descriptives with two panels.
    I am using pweights, and in the second panel a factor variable with three age groups.

    When run the two lines with dtable separately, the i.age_grp factor variable correctly shows four rows: 'Age group' and then followed by three rows with the count and percentages of counts.

    For some reason, when I try to combine the two tables into one, running the last line shows all the rows present in the separate tables except the four rows relating to the factor variable.

    Code:
    dtable depvar1 depvar2 [pweight=indivwgt], sample(, statistics(frequency)) name(panelA)
    
    dtable male age i.age_grp any_educ [pweight=indivwgt], factor(age_grp, statistics(fvfreq fvpercent)) name(panelB)
    
    collect combine all = panelA panelB
    collect layout (collection#var) (result)
    When I run
    Code:
    collect levelsof var
    it correctly shows the 1.age_grp 2.age_grp 3.age_grp included in the levels.

    I tried running things like
    Code:
    collect layout (collection[panelB]#var[i.age_grp]) (result)
    and
    Code:
    collect layout (collection[panelB]#var[1.age_grp 2.age_grp 3.age_grp]) (result)
    , but I get 'Your layout specification does not identify any items'.

  • #2
    Providing some data with your code helps expedite our efforts to help you.
    "Help me, help you."
    --Jerry Maquire
    The problem is in the composite result named _dtable_stats defined in the first collection named panelA. It does not contain the factor variable statistics that are used in the second collection named panelB. By default, collect combine uses the first (left-most) style properties when combining collections, but you can use option style(right) to force it to allow subsequent (right-most) style properties to be used instead. This will solve your problem because the definition for composite _dtable_stats in the second collection named panelB contains the statistics used in both collections.

    Code:
    collect combine all = panelA panelB, style(right)

    Comment

    Working...
    X