Announcement

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

  • Display selected category + all categories combined

    Hi

    I think this question has a really simple answer but I can't for the life of me work it out or find one online.

    I'm trying to create a bar chart displaying values of a continuous variable stratified by age group (three categories) and by two comparison groups. The comparison groups I'm interested in are:
    • (A) all those in one category of an ordinal variable, and
    • (B) everyone in dataset, regardless of their value for this variable.
    To make it clearer, the ordinal variable in question is quintiles of an index of multiple deprivation, so I want to compare:
    • (A) those living in most deprived area (IMD=1)
    • (B) the entire population (IMD=1-5)
    I'm not interested in seeing the other categories on their own (i.e. I don't want to see bars for IMD=2, IMD=3, etc).

    I can't seem to find a way to specify this using syntax. If I use if, I only get one category. If I use by/over, I get all of them. I've tried creating a dummy variable for SIMD=1 with SIMD~=1 set to missing and using total, but this leaves out the missing from the total.

    I'm sure I'm missing something really obvious - any advice as to how to write this in syntax would be very gratefully received

    Many thanks

    Emily


  • #2
    This isn't very clear to me. You don't give a data example and I have trouble knowing what you want to plot.

    If giving a data example is not practical, you should be able to phrase your question in terms of some standard dataset such as the auto data.

    Do you, as you say, really want to show the values of a continuous variable (not named here) with a bar chart? How many values do you have?

    Stratification is a separate issue.

    See

    SJ-14-1 gr0058 . . . . . Stata tip 119: Expanding datasets for graphical ends
    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
    Q1/14 SJ 14(1):230--235 (no commands)
    tip on using the expand command for graphics

    https://www.stata-journal.com/sjpdf....iclenum=gr0058

    You'll need a data structure in which one category is your category of interest and the other category is all the data. That necessarily implies that some observations appear twice. You can get that. The trick as just mentioned is to use expand.

    I can see why you want to do that for reductions of your data (see the paper just cited) but not for original continuous values.

    Comment


    • #3
      Hi Nick

      Thanks very much for this helpful response - apologies for the slow reply but I've been away.

      Stratification is the issue, as you correctly identify. Tip 119 was very helpful, as the first example is very similar to what I am trying to do. I've now worked out how to do it using expand - thanks.

      Emily

      Comment

      Working...
      X