Announcement

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

  • Excluding data

    Hi, I wonder if anyone can help?

    IM1 = does the child have a vacciantion card?
    CAGE_6 = 6 month age categories

    Commands:

    tab IM1, nol m
    replace IM1 = . if IM1 == 9
    tab IM1 CAGE_6

    I want to exclude children in the 36-47 month old category for the variable IM1, how do I do this please? I can't drop the data as I am measuring many variables of each child.

  • #2
    I'm guessing that CAGE_6 = 7 corresponds to 36-41 months and CAGE_6 = 8 to 42-47 months, and guessing you don't have any larger values of CAGE_6.
    Code:
    tab IM1 CAGE_6 if CAGE_6<7

    Comment


    • #3
      Originally posted by William Lisowski View Post
      I'm guessing that CAGE_6 = 7 corresponds to 36-41 months and CAGE_6 = 8 to 42-47 months, and guessing you don't have any larger values of CAGE_6.
      Code:
      tab IM1 CAGE_6 if CAGE_6<7
      Thank you Willian. I obviously didn't ask my question correctly, what I'm looking to do is drop the children aged over 36 months from the IM1 variable, without using the 'drop command' which loses sample cases for all other variables too

      Comment


      • #4
        I do not know what you mean by "drop the children aged over 36 months from the IM1 variable".

        In Stata the drop command has two different meanings.

        The first, which is not what you want, is to "drop a variable" by removing the variable from every observation of your dataset.

        The second, which is also not what you want, is to "drop an observation" by removing the observation from every variable in your dataset.

        The drop command cannot remove some observations of some variables. In Stata, every observation of every variable has a value for that variable in that observation. The value can be a Stata missing value, as you used in post #1 to replace the values of IM1 that were 9 in your data.

        So the drop command is not what you want.

        In post #2 I showed code that used the if qualifier to run the tab command omitting the observations for which CAGE_6 is 7 or 8, which I wrote that I assumed meant age was 36 months or greater. If my assumption was wrong, you need to better describe the values of CAGE_6.

        If you want to always omit observations for which CAGE_6 is 7 or 8 in any command in which it appears, something like the following, which is similar to your code for IM1 in post #1, might work. I create a new variable CAGE_6b so that if you later find you need to know about the children 36 months and over you still have the original data.
        Code:
        clonevar CAGE_6b = CAGE_6
        replace CAGE_6b = . if CAGE_6b==7
        replace CAGE_6b = . if CAGE_6b==8
        tab IM1 CAGE_6b

        Comment

        Working...
        X