Announcement

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

  • Question about chi-square test

    Hello, I posted a question earlier today, but didn't get any reply. So I'm trying to rephrase my question for an answer. I've merged 2 datasets based on their ID number. There were 658 matched and 94 non-matched participants, so I had to delete the 94 participants from my final analyses. However, if I want to see if there is any significant difference between the 2 groups who were included (658) and not included (94) in the final analysis, how can I do that? I need to check the difference for some variables, say, if there is any difference in the gender, parity, maternal age between the 2 groups or not? I've been told to do ch-square analysis between the 2 groups for different variables, but I'm not sure how to do that. Can someone please help me? Thanks.

    Fahmida

  • #2
    I doubt anybody will be able to answer your question without seeing an example of your data set, including observations from both groups. Use the -dataex- command to do that. And be sure to explain which variable in your data set defines the two groups.

    By the way, from your description it sounds like your data consists of matched pairs rather than two groups. If so, the ordinary chi square would be inappropriate. And as far as continuous variables like maternal age, the chi square test is also not appropriate. So show example data, and explain more clearly.

    If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.



    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Hello,

      Sorry for the confusion. here is the example of the dataset-
      input str4 hsn byte(bqbwheez bqbasth bqbnose bqbitchyeyes) double(mage age_cat edu_cat) long csex double preterm
      "1004" 0 0 0 . 18.18858447488583 1 1 2 0
      "1005" 0 0 0 . 27.494520547945285 2 1 2 0
      "1007" 0 0 1 0 21.318493150684844 1 1 1 0
      "1009" 0 0 0 . 37.57511415525096 3 1 1 0
      "1013" 1 0 0 . 22.077853881278543 1 2 1 0
      "1021" 1 0 0 . 25.439726027397228 2 4 1 0
      "1023" 0 0 1 0 23.833333333333258 1 1 2 0
      "1024" 0 0 0 . 18.478082191780913 1 2 1 0
      "1027" 0 0 0 . 25.64474885844743 2 2 2 1
      "1028" 0 0 0 . 29.09977168949763 2 2 2 0
      "1029" 0 0 0 . 23.569634703196243 1 4 1 0
      "1031" 0 0 0 . 28.458904109588957 2 2 2 0
      "1032" 0 0 0 . 19.26917808219173 1 2 2 0
      "1033" 0 0 0 . 19.69680365296813 1 1 1 0
      "1034" 1 0 0 . 19.872831050228342 1 1 1 0
      "1035" 1 1 0 . 35.944063926940544 3 1 2 0
      "1037" 0 0 0 . 27.18584474885847 2 1 1 0
      "1049" 0 0 0 . 21.975342465753556 1 2 2 0

      As you can see, bqbithcyeyes varibale has some missing values for some hsn. Now I need to see if there is any difference in some variables (mage, age_cat etc) based on this bqbitchyeyes, as I'll delete those participants who have missing bqbitchyeyes. That said, I need to see the difference between those participants who have and don't have bqbitchyeyes data. Just the thing is there are more variables like bqbitchyeyes whose values are missing (e.e. bqbwheez bqbasth bqbnos), so I need to delete them all from my dataset. Now my question is, how can I do the comparison between those participants who in the dataset and who will be dropped from the dataset based on these bqbwheez bqbasth bqbnose bqbitchyeyes etc variables having missing value? Thanks.

      Fahmida

      Comment


      • #4
        Well unless the observations that have missing values for itchy eyes are exactly the same ones that have missing values for the other variables, removing them from the data set is a bad idea: you woule end up having to re-load the data for each analysis. Better is to use an -if- condition to exclude them from each analysis. Actually, you don't even have to do that with most of the statistical tests. For example to compare mage between those with and without itchy eyes, all you have to do is

        Code:
        ttest mage, by(bqbitchyeyes)
        This will give you a ttest comparing those two groups on this variable (which is clearly a continuous variable). And the exclusion of those with missing values for bqbitchyeyes (or, for that matter, missing values for mage) is automatically done for you.

        Note: The above code will not run in your example data because in the example, bqbitchyeyes is always 0 when it isn't missing. To compare two groups, you actually need two groups. I assume that in your full data, there are observations where bqbitchyeyes is neither 0 nor missing. (If that's not true, then you don't have two groups and either your data management somehow failed to create them, or your data are simply not suitable for this kind of comparison at all.)

        The other variables age_cat, edu_cat, csex, and preterm look categorical. So those lend themselves to a chi square test.

        Code:
        tab age_cat bqbitchyeyes, col chi2
        will handle it (and analogous commands for the others.)


        Comment


        • #5
          Just a side note, after Clyde’s insightful reply.

          You can create a binary (‘dummy’) variable, say, matched. After that, you can perform tests (chi-squared, Student, etc.) ‘by’ the binary variable, provided there are values for both categories.
          Best regards,

          Marcos

          Comment


          • #6
            Thanks a lot guys! I really appreciate your advice and suggestions.

            Fahmida

            Comment

            Working...
            X