Announcement

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

  • #61
    Thanks a lot, Carlo. I will take a look at teffects psmatch.

    Best,

    Raj

    Comment


    • #62
      Dear all,

      I'm analyzing data from a comparative cross-sectional study and i found difference in age, weight and length between children of both groups. Now, i want to rerun the analysis by matching each single case with each single control by sex and age. I would not do an exact age matching, but want to match each case with a control in the nearest age. Age here is in months.

      This is how i proceeded based on previous posts:
      preserve

      keep if GROUPE == 2

      rename * *_control

      rename AGEENFCAL_COR_control age

      rename SEXENF_control sexe

      tempfile controls

      save `controls'

      restore

      keep if GROUPE == 1

      rename * *_case

      rename AGEENFCAL_COR_case age

      rename SEXENF_case sexe

      rangejoin age -0.25 0.25 using `controls', by(sex)

      set seed 1234

      gen double shuffle = runiform()

      by IDENF_case (shuffle), sort: keep if _n == 1

      drop shuffle

      My issue is that there is some control id matching with different cases while i want each case to have a separate control.

      It's my first time to do this kind of analysis using Stata.

      How do i proceed?

      Comment


      • #63
        Your description of how you handle age is not consistent with the code you show. You say that you want to match the closest age. But what your code actually does is choose a random match from among those where age agrees to within +/- 0.25.

        As for wanting each case to have a separate control, it can be done, but it is a little complicated. And there is no statistical reason to do that. And it could mean that you will end up with no match at all for some cases that currently have a match. Do you have a particular reason for wanting this?

        If you have a good reason for requiring separate controls for each case, when you post back, please show example data, and use the -dataex- command to do that. 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


        • #64
          Dear Clyde,
          Thank you for your answer. Here is example data using -dataex-
          dataex IDENF GROUPE AGEENFCAL_COR SEXENF LAZ2 WLZ2 GRLAZ2G

          ----------------------- copy starting from the next line -----------------------
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str10 IDENF byte GROUPE float AGEENFCAL_COR byte SEXENF double(LAZ2 WLZ2 GRLAZ2G)
          "04021RM01" 1  11.47541 1   .61 -1.22 2
          "04011NF17" 1 13.836065 1 -1.18  -.58 2
          "03021NM03" 1  21.27869 2  -.83 -1.14 2
          "01021SD01" 1        12 1   .26  -.43 2
          "02011WN07" 1 11.442623 1  -.86 -2.01 2
          "01021SK09" 1  9.639344 1  -.79 -1.44 2
          "01021KN08" 1 20.590164 2 -1.43  -.69 2
          "01011MN08" 1 13.672132 2  -.34   1.8 2
          "04021SD12" 1  9.442623 2  -.73  -.79 2
          "01021AG12" 1 18.131147 2  -.66  -.68 2
          "04021DK13" 1 11.836065 1  -1.1  -.17 2
          "01021OD14" 1  13.80328 1  3.01   .44 2
          "02021AG07" 1  12.62295 2   .65  -.57 2
          "01021SF02" 1 11.442623 2   .53   .83 2
          "02021YD01" 1  9.803279 2   .59   .05 2
          "02021DN14" 1  9.180327 1  -.91  -.68 2
          "04021DD08" 1 11.508197 2   .74 -2.11 2
          "04011ON09" 1 10.721312 2 -1.09   -.4 2
          "03011MD11" 1 17.868853 2 -1.14 -1.05 2
          "02011AD04" 1  10.52459 2 -1.05 -1.27 2
          "04011BN03" 1  11.57377 1   .38   .58 2
          "04021MS04" 1 10.688524 2   .37  -.97 2
          "03011OS05" 1 16.491804 2 -1.36 -1.42 2
          "04021CF06" 1 11.606558 2 -1.13   .01 2
          "01021DS03" 1  11.57377 2 -1.48  -.01 2
          "04011NM05" 1 11.639344 1 -1.34 -2.73 2
          "04021AS11" 1 13.934426 2   .24  -.43 2
          "03011FD08" 1  9.836065 1   1.8  1.28 2
          "04011RD06" 1  15.14754 1 -2.99 -2.19 1
          "04011MS01" 1  12.09836 2 -2.11 -2.28 1
          "03011DD07" 1  12.42623 1  -.69   .82 2
          "04011AT12" 1 12.983606 1  -.92 -1.03 2
          "04011AS15" 1 10.819673 1 -1.06   .05 2
          "02021AS15" 1 10.360656 2  -.56  -.45 2
          "03011AD10" 1 18.950819 1  -.12  -.51 2
          "02021AS10" 1 19.049181 2  1.06 -2.03 2
          "01011AC03" 1  12.19672 2  -1.1  2.37 2
          "03021AN02" 1 14.688524 1  -.99  -.51 2
          "04021OD10" 1 11.836065 2  -.76 -1.49 2
          "04021AB02" 1 11.868853 1   1.6  -.05 2
          "03021SS10" 1 14.459017 1 -1.01  -.04 2
          "04011NM14" 1 10.754098 1 -1.22  -.76 2
          "04011DG02" 1 12.983606 2  1.28   .55 2
          "03021FD11" 1  13.90164 1  -.58  -.89 2
          "04011NF16" 1 13.836065 2  -.16   .07 2
          "01011KC01" 1 11.770492 2 -1.46  1.32 2
          "03021MS05" 1  9.344262 2  1.12  1.68 2
          "03011NK06" 1 19.049181 2 -1.54 -1.53 2
          "03021AF06" 1  14.85246 1  -.17   .84 2
          "03021FD09" 1 14.655738 1  -.07  -.66 2
          "03021AD04" 1 11.180327 2  -.25   .88 2
          "03011AG04" 1  20.85246 2 -1.09  -.51 2
          "04011VM11" 1 14.983606 2   .72 -1.16 2
          "01021FD04" 1  12.42623 2  -.63  -.14 2
          "04011AN07" 1 18.065575 1 -2.24 -1.15 1
          "02021NB05" 1 11.704918 2   .25  -.25 2
          "03021AD14" 1 15.540983 2  -.01 -1.54 2
          "02011NT06" 1  9.967213 2  -.17 -1.79 2
          "02021YS12" 1 10.327868 2  -.24    .9 2
          "01021TT05" 1 15.540983 1 -1.22  -2.4 2
          "03011DB09" 1 11.213115 2   .55  -.66 2
          "03021KN07" 1 11.639344 2   .65  -.58 2
          "02011MC17" 1  9.639344 1    -1 -1.34 2
          "03011AB01" 1 11.868853 1  1.22  -.18 2
          "01021AF07" 1 19.344263 1  -.26  -.81 2
          "04011NM18" 1 18.786884 1  -.36  -.93 2
          "03021RS12" 1 10.459017 1  -.53  2.34 2
          "01011KD04" 1 11.704918 1 -1.12 -1.98 2
          "02021MD04" 1 11.442623 2   .21   .28 2
          "04021DF03" 1 11.344262 1   .42 -2.12 2
          "02021ND16" 1 17.344263 1  -.83 -1.78 2
          "02011AC15" 1 11.016394 1  -.24  -.38 2
          "02011SB02" 1 10.754098 2  2.24   .62 2
          "01021SN16" 1 17.180328 1  -.96 -1.11 2
          "02011FN01" 1  21.47541 2  -1.2 -1.58 2
          "01011FF16" 1 10.491803 2  -.32  -.44 2
          "02011KM21" 1  9.967213 1   .69  -.87 2
          "04011NF10" 1 20.655737 2 -1.47 -1.27 2
          "01011AB13" 1  10.52459 2   .26 -1.55 2
          "01011KD05" 1 11.704918 2   .14 -1.06 2
          "01011KK10" 1 12.786885 2  -.73   1.8 .
          "02021FD06" 1 11.311476 1 -2.79 -1.04 1
          "01021KN10" 1 12.688524 2   .92  1.67 2
          "02021SD09" 1  22.32787 2   .25  -.71 2
          "01021KS13" 1  9.868853 1  -.94   -.1 2
          "04021FF09" 1 10.295082 2   .31  -.43 2
          "02011NG08" 1  11.80328 1  -1.1   .77 2
          "02011DS14" 1 13.639344 1 -1.77  -.42 2
          "02011AT12" 1  9.770492 1  -.47  -.18 2
          "03021MD01" 1        20 1  -.05  -.24 2
          "04021YN07" 1 11.934426 1   .05 -1.78 2
          "02021FT03" 1 20.459017 2   .07 -2.25 2
          "02021AG08" 1  12.62295 1    .8   .53 2
          "03021NS13" 1 10.983606 1 -1.94   .73 2
          "01011RB09" 1 14.557377 2  -.54  -.31 2
          "03011HD02" 1 18.393442 2  -.63  -.85 2
          "03011MS12" 1 16.688524 1  -.77  -.75 2
          "01011KD07" 1 11.311476 1  -1.8  -.82 2
          "03011OS03" 1  11.80328 2  -.08  -.91 2
          "02011AN16" 1 11.967213 1  -.37  -.26 2
          end
          ------------------ copy up to and including the previous line ------------------

          Listed 100 out of 229 observations
          Use the count() option to list more

          I want each case to have a separate control by age and sex to verify if the observed difference between my two groups regarding nutritional indicators is remained or not after matching. I have younger children in GROUPE==1 and older in GROUPE==2. So if there is separate match, younger children will be left in GROUPE1 and older in GROUPE2.

          Thank you in advance for your response.

          Comment


          • #65
            Clarifications,

            GRLAZ2G is the variable for stunting
            LAZ2 is the variable for Length-for-age in z-scores
            WLZ2 is the variable for weight-for-length in z-scores
            GROUPE is coded 1 (Supplemented with vitamin A) and 2 (not supplemented with vitamin A)

            Thanks

            Comment


            • #66
              Your example data cannot be used for this purpose because all of the observations have GROUPE == 1, so no matching can be done. Please post back with a data example that includes observations from both groups, and for which several of the case observations will have more than one matchable control.

              Comment


              • #67
                Sorry,
                I'm posting another sample data

                . dataex IDENF GROUPE SEXENF AGEENFCAL_COR LAZ2 WLZ2 GRLAZ2G, count (180)

                ----------------------- copy starting from the next line -----------------------
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input str10 IDENF byte(GROUPE SEXENF) float AGEENFCAL_COR double(LAZ2 WLZ2 GRLAZ2G)
                "01011AB13" 1 2  10.52459   .26 -1.55 2
                "01011AC03" 1 2  12.19672  -1.1  2.37 2
                "01011AC12" 1 1 14.819673  -2.3   .24 1
                "01011AD11" 1 2  9.934426  -.13  -.28 2
                "01011AD15" 1 1 10.327868  -.23   .11 2
                "01011FF16" 1 2 10.491803  -.32  -.44 2
                "01011KC01" 1 2 11.770492 -1.46  1.32 2
                "01011KD04" 1 1 11.704918 -1.12 -1.98 2
                "01011KD05" 1 2 11.704918   .14 -1.06 2
                "01011KD06" 1 1 11.836065 -1.55 -1.45 2
                "01011KD07" 1 1 11.311476  -1.8  -.82 2
                "01011KK10" 1 2 12.786885  -.73   1.8 .
                "01011MN08" 1 2 13.672132  -.34   1.8 2
                "01011MS14" 1 1  9.540983 -1.66  -.65 2
                "01011NN02" 1 1 12.393442  2.44  1.38 2
                "01011RB09" 1 2 14.557377  -.54  -.31 2
                "01012AD08" 2 2 14.065574  -.54  -.96 2
                "01012AN15" 2 2 14.327868 -1.72 -1.23 2
                "01012AS02" 2 2 13.868853 -1.39 -1.49 2
                "01012BD10" 2 1 14.032787   -.5   .12 2
                "01012CD05" 2 1 16.983606  1.45  -.42 2
                "01012FC12" 2 2 12.327868  -.84  -.89 2
                "01012FS09" 2 1  11.04918 -1.69  -.17 2
                "01012KS14" 2 2  9.147541   .73 -1.94 2
                "01012MC11" 2 1 11.278688  -.09   .05 2
                "01012MD04" 2 2 14.262295   .46   1.4 2
                "01012MD13" 2 1  11.47541   .15  -.69 2
                "01012MF06" 2 1 16.065575  1.01    .5 2
                "01012NS03" 2 2  15.04918   .31  -.87 2
                "01012RD01" 2 1  15.14754 -2.11  -.87 1
                "01012SG16" 2 1 15.245902  -.18   .28 2
                "01021AF07" 1 1 19.344263  -.26  -.81 2
                "01021AG12" 1 2 18.131147  -.66  -.68 2
                "01021DS03" 1 2  11.57377 -1.48  -.01 2
                "01021FD04" 1 2  12.42623  -.63  -.14 2
                "01021KN08" 1 2 20.590164 -1.43  -.69 2
                "01021KN10" 1 2 12.688524   .92  1.67 2
                "01021KS13" 1 1  9.868853  -.94   -.1 2
                "01021NN17" 1 1 12.688524  -.79   -.3 2
                "01021OD14" 1 1  13.80328  3.01   .44 2
                "01021RD15" 1 1 15.442623  -.34   -.8 2
                "01021SD01" 1 1        12   .26  -.43 2
                "01021SF02" 1 2 11.442623   .53   .83 2
                "01021SK09" 1 1  9.639344  -.79 -1.44 2
                "01021SK11" 1 2 12.065574   .47   .22 2
                "01021SN16" 1 1 17.180328  -.96 -1.11 2
                "01021TT05" 1 1 15.540983 -1.22  -2.4 2
                "01022AG13" 2 2 19.737705   -.2   .74 2
                "01022AS08" 2 2 15.344262  -.98   .47 2
                "01022AT02" 2 2  19.14754   .16  -.37 2
                "01022BK01" 2 1 12.590164   .61  -.51 2
                "01022DD14" 2 2  22.81967  -.28  -.92 2
                "01022FD06" 2 1 19.442623 -1.12 -1.03 2
                "01022FS11" 2 1 14.491803   .85   -.1 2
                "01022HB03" 2 1 19.836065   -.2   .16 2
                "01022MG12" 2 2 13.311476   .69   .99 2
                "01022MS07" 2 1 11.868853   .75  1.71 2
                "01022NL04" 2 2 20.786884  -.49  -1.9 2
                "01022NM10" 2 2 16.590164  1.14   .55 2
                "01022NS09" 2 2         9 -1.58 -1.86 2
                "02011AC15" 1 1 11.016394  -.24  -.38 2
                "02011AD04" 1 2  10.52459 -1.05 -1.27 2
                "02011AF05" 1 2  13.47541  -.32  -.42 2
                "02011AN16" 1 1 11.967213  -.37  -.26 2
                "02011AT12" 1 1  9.770492  -.47  -.18 2
                "02011DS14" 1 1 13.639344 -1.77  -.42 2
                "02011FB18" 1 2         9 -1.46  -.09 2
                "02011FN01" 1 2  21.47541  -1.2 -1.58 2
                "02011KM21" 1 1  9.967213   .69  -.87 2
                "02011MC17" 1 1  9.639344    -1 -1.34 2
                "02011NG08" 1 1  11.80328  -1.1   .77 2
                "02011NK22" 1 1  21.96721  -.86 -1.29 2
                "02011NT06" 1 2  9.967213  -.17 -1.79 2
                "02011SB02" 1 2 10.754098  2.24   .62 2
                "02011TO03" 1 2 11.704918   .27  -.14 2
                "02011WN07" 1 1 11.442623  -.86 -2.01 2
                "02012AB07" 2 1  9.311476 -1.38  -.53 2
                "02012AF01" 2 2 16.131147  -.43 -2.16 2
                "02012BB02" 2 2 19.540983  -.55  -.28 2
                "02012ED04" 2 2  22.19672  -2.6 -2.52 1
                "02012LS06" 2 2  22.39344  -1.2 -2.07 2
                "02012MD05" 2 2  19.90164  1.21  -.23 2
                "02012NC03" 2 1 13.737705  -.66  -.93 2
                "02021AG07" 1 2  12.62295   .65  -.57 2
                "02021AG08" 1 1  12.62295    .8   .53 2
                "02021AS10" 1 2 19.049181  1.06 -2.03 2
                "02021AS15" 1 2 10.360656  -.56  -.45 2
                "02021DN14" 1 1  9.180327  -.91  -.68 2
                "02021FD06" 1 1 11.311476 -2.79 -1.04 1
                "02021FT03" 1 2 20.459017   .07 -2.25 2
                "02021KT02" 1 2 11.409836    .1   -.8 2
                "02021MD04" 1 2 11.442623   .21   .28 2
                "02021NB05" 1 2 11.704918   .25  -.25 2
                "02021ND16" 1 1 17.344263  -.83 -1.78 2
                "02021OS13" 1 2  10.42623  2.88   -.8 2
                "02021SD09" 1 2  22.32787   .25  -.71 2
                "02021YD01" 1 2  9.803279   .59   .05 2
                "02021YS12" 1 2 10.327868  -.24    .9 2
                "02022AD11" 2 1  13.90164   -.8  -.77 2
                "02022AG07" 2 2 12.688524   .29  1.23 2
                "02022AM05" 2 1 11.934426  1.17  2.15 2
                "02022AM06" 2 1 13.245902 -1.09  -.96 2
                "02022CD10" 2 2 13.639344   .52  -.63 2
                "02022DD15" 2 1 11.704918 -2.66  -.64 1
                "02022ES01" 2 2 12.983606   .05   .98 2
                "02022FG12" 2 2 16.393442   -.7  -.46 2
                "02022FN02" 2 2 17.245901  -.06   .29 2
                "02022MS03" 2 2 16.819672 -1.99  -.12 2
                "02022ND08" 2 1 23.016394 -2.18 -2.11 1
                "02022NH14" 2 2  10.09836 -1.05   .33 2
                "02022NK09" 2 1 12.557377 -1.74   .33 2
                "02022SD13" 2 1 11.016394 -2.32 -1.15 1
                "02022SS04" 2 1 10.065574   .52   .25 2
                "03011AB01" 1 1 11.868853  1.22  -.18 2
                "03011AD10" 1 1 18.950819  -.12  -.51 2
                "03011AG04" 1 2  20.85246 -1.09  -.51 2
                "03011DB09" 1 2 11.213115   .55  -.66 2
                "03011DD07" 1 1  12.42623  -.69   .82 2
                "03011FD08" 1 1  9.836065   1.8  1.28 2
                "03011HD02" 1 2 18.393442  -.63  -.85 2
                "03011MD11" 1 2 17.868853 -1.14 -1.05 2
                "03011MS12" 1 1 16.688524  -.77  -.75 2
                "03011NK06" 1 2 19.049181 -1.54 -1.53 2
                "03011OS03" 1 2  11.80328  -.08  -.91 2
                "03011OS05" 1 2 16.491804 -1.36 -1.42 2
                "03012AB04" 2 1 21.081966 -1.11   .62 2
                "03012AD10" 2 1 15.180327 -1.24 -1.39 2
                "03012AN13" 2 2  20.81967  -.34 -1.46 2
                "03012AT15" 2 1 23.737705 -1.51   .39 2
                "03012DD14" 2 1 13.737705 -1.34 -1.52 2
                "03012FB09" 2 2 13.016394  -.56 -1.08 2
                "03012FD01" 2 1  15.14754   .49    .6 2
                "03012FN08" 2 2 19.508196  -.33  -.44 2
                "03012JN03" 2 1 13.770492  2.09  2.45 2
                "03012KN06" 2 1 23.344263  -1.2 -1.45 2
                "03012KS12" 2 1  9.836065  -.11 -1.13 2
                "03012RB02" 2 2  22.95082 -3.23 -1.96 1
                "03012RD05" 2 2 18.819672 -2.37  -.46 1
                "03012SM07" 2 2 15.180327  -.71   .01 2
                "03012SM11" 2 1 17.049181  -.37  -.55 2
                "03021AD04" 1 2 11.180327  -.25   .88 2
                "03021AD14" 1 2 15.540983  -.01 -1.54 2
                "03021AF06" 1 1  14.85246  -.17   .84 2
                "03021AN02" 1 1 14.688524  -.99  -.51 2
                "03021FD09" 1 1 14.655738  -.07  -.66 2
                "03021FD11" 1 1  13.90164  -.58  -.89 2
                "03021KN07" 1 2 11.639344   .65  -.58 2
                "03021MD01" 1 1        20  -.05  -.24 2
                "03021MS05" 1 2  9.344262  1.12  1.68 2
                "03021NM03" 1 2  21.27869  -.83 -1.14 2
                "03021NM08" 1 2 12.032787   .27   .77 2
                "03021NS13" 1 1 10.983606 -1.94   .73 2
                "03021RS12" 1 1 10.459017  -.53  2.34 2
                "03021SS10" 1 1 14.459017 -1.01  -.04 2
                "03022AD13" 2 2  9.081967  1.16   .52 2
                "03022AK07" 2 1  9.245902  -2.9   .25 1
                "03022AS11" 2 1  20.22951  -2.7 -2.13 1
                "03022CD12" 2 2  20.85246 -2.35 -1.68 1
                "03022CN02" 2 2 12.590164   .29  -1.2 2
                "03022KF04" 2 1 12.557377 -1.83 -2.44 2
                "03022LD06" 2 2 18.885246   .91   .97 2
                "03022MT03" 2 2  23.90164   .13 -1.25 2
                "03022ND08" 2 1 14.131147  1.25  -.93 2
                "03022ND10" 2 2  20.19672  1.02   .19 2
                "03022NM09" 2 1 12.163935   .38    .1 2
                "03022NS14" 2 1 10.032787  -.46   .24 2
                "03022NS15" 2 1 10.032787  -.75    .3 2
                "03022OB01" 2 2 16.885246   .19  1.31 2
                "03022ON05" 2 1 13.180327 -1.32  -.93 2
                "04011AN07" 1 1 18.065575 -2.24 -1.15 1
                "04011AS15" 1 1 10.819673 -1.06   .05 2
                "04011AT12" 1 1 12.983606  -.92 -1.03 2
                "04011AT13" 1 2 14.590164     0  -.33 2
                "04011BN03" 1 1  11.57377   .38   .58 2
                "04011DG02" 1 2 12.983606  1.28   .55 2
                "04011MS01" 1 2  12.09836 -2.11 -2.28 1
                "04011NF10" 1 2 20.655737 -1.47 -1.27 2
                "04011NF16" 1 2 13.836065  -.16   .07 2
                "04011NF17" 1 1 13.836065 -1.18  -.58 2
                "04011NM05" 1 1 11.639344 -1.34 -2.73 2
                end
                ------------------ copy up to and including the previous line ------------------

                Comment


                • #68
                  Well, as I said before, there is no reason to do this. The question you are pursuing can be equally well answered without the extra trouble of preventing re-use of controls for different cases. But here is how you do it anyway:

                  Code:
                  * Example generated by -dataex-. To install: ssc install dataex
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input str10 IDENF byte(GROUPE SEXENF) float AGEENFCAL_COR double(LAZ2 WLZ2 GRLAZ2G)
                  "01011AB13" 1 2  10.52459   .26 -1.55 2
                  "01011AC03" 1 2  12.19672  -1.1  2.37 2
                  "01011AC12" 1 1 14.819673  -2.3   .24 1
                  "01011AD11" 1 2  9.934426  -.13  -.28 2
                  "01011AD15" 1 1 10.327868  -.23   .11 2
                  "01011FF16" 1 2 10.491803  -.32  -.44 2
                  "01011KC01" 1 2 11.770492 -1.46  1.32 2
                  "01011KD04" 1 1 11.704918 -1.12 -1.98 2
                  "01011KD05" 1 2 11.704918   .14 -1.06 2
                  "01011KD06" 1 1 11.836065 -1.55 -1.45 2
                  "01011KD07" 1 1 11.311476  -1.8  -.82 2
                  "01011KK10" 1 2 12.786885  -.73   1.8 .
                  "01011MN08" 1 2 13.672132  -.34   1.8 2
                  "01011MS14" 1 1  9.540983 -1.66  -.65 2
                  "01011NN02" 1 1 12.393442  2.44  1.38 2
                  "01011RB09" 1 2 14.557377  -.54  -.31 2
                  "01012AD08" 2 2 14.065574  -.54  -.96 2
                  "01012AN15" 2 2 14.327868 -1.72 -1.23 2
                  "01012AS02" 2 2 13.868853 -1.39 -1.49 2
                  "01012BD10" 2 1 14.032787   -.5   .12 2
                  "01012CD05" 2 1 16.983606  1.45  -.42 2
                  "01012FC12" 2 2 12.327868  -.84  -.89 2
                  "01012FS09" 2 1  11.04918 -1.69  -.17 2
                  "01012KS14" 2 2  9.147541   .73 -1.94 2
                  "01012MC11" 2 1 11.278688  -.09   .05 2
                  "01012MD04" 2 2 14.262295   .46   1.4 2
                  "01012MD13" 2 1  11.47541   .15  -.69 2
                  "01012MF06" 2 1 16.065575  1.01    .5 2
                  "01012NS03" 2 2  15.04918   .31  -.87 2
                  "01012RD01" 2 1  15.14754 -2.11  -.87 1
                  "01012SG16" 2 1 15.245902  -.18   .28 2
                  "01021AF07" 1 1 19.344263  -.26  -.81 2
                  "01021AG12" 1 2 18.131147  -.66  -.68 2
                  "01021DS03" 1 2  11.57377 -1.48  -.01 2
                  "01021FD04" 1 2  12.42623  -.63  -.14 2
                  "01021KN08" 1 2 20.590164 -1.43  -.69 2
                  "01021KN10" 1 2 12.688524   .92  1.67 2
                  "01021KS13" 1 1  9.868853  -.94   -.1 2
                  "01021NN17" 1 1 12.688524  -.79   -.3 2
                  "01021OD14" 1 1  13.80328  3.01   .44 2
                  "01021RD15" 1 1 15.442623  -.34   -.8 2
                  "01021SD01" 1 1        12   .26  -.43 2
                  "01021SF02" 1 2 11.442623   .53   .83 2
                  "01021SK09" 1 1  9.639344  -.79 -1.44 2
                  "01021SK11" 1 2 12.065574   .47   .22 2
                  "01021SN16" 1 1 17.180328  -.96 -1.11 2
                  "01021TT05" 1 1 15.540983 -1.22  -2.4 2
                  "01022AG13" 2 2 19.737705   -.2   .74 2
                  "01022AS08" 2 2 15.344262  -.98   .47 2
                  "01022AT02" 2 2  19.14754   .16  -.37 2
                  "01022BK01" 2 1 12.590164   .61  -.51 2
                  "01022DD14" 2 2  22.81967  -.28  -.92 2
                  "01022FD06" 2 1 19.442623 -1.12 -1.03 2
                  "01022FS11" 2 1 14.491803   .85   -.1 2
                  "01022HB03" 2 1 19.836065   -.2   .16 2
                  "01022MG12" 2 2 13.311476   .69   .99 2
                  "01022MS07" 2 1 11.868853   .75  1.71 2
                  "01022NL04" 2 2 20.786884  -.49  -1.9 2
                  "01022NM10" 2 2 16.590164  1.14   .55 2
                  "01022NS09" 2 2         9 -1.58 -1.86 2
                  "02011AC15" 1 1 11.016394  -.24  -.38 2
                  "02011AD04" 1 2  10.52459 -1.05 -1.27 2
                  "02011AF05" 1 2  13.47541  -.32  -.42 2
                  "02011AN16" 1 1 11.967213  -.37  -.26 2
                  "02011AT12" 1 1  9.770492  -.47  -.18 2
                  "02011DS14" 1 1 13.639344 -1.77  -.42 2
                  "02011FB18" 1 2         9 -1.46  -.09 2
                  "02011FN01" 1 2  21.47541  -1.2 -1.58 2
                  "02011KM21" 1 1  9.967213   .69  -.87 2
                  "02011MC17" 1 1  9.639344    -1 -1.34 2
                  "02011NG08" 1 1  11.80328  -1.1   .77 2
                  "02011NK22" 1 1  21.96721  -.86 -1.29 2
                  "02011NT06" 1 2  9.967213  -.17 -1.79 2
                  "02011SB02" 1 2 10.754098  2.24   .62 2
                  "02011TO03" 1 2 11.704918   .27  -.14 2
                  "02011WN07" 1 1 11.442623  -.86 -2.01 2
                  "02012AB07" 2 1  9.311476 -1.38  -.53 2
                  "02012AF01" 2 2 16.131147  -.43 -2.16 2
                  "02012BB02" 2 2 19.540983  -.55  -.28 2
                  "02012ED04" 2 2  22.19672  -2.6 -2.52 1
                  "02012LS06" 2 2  22.39344  -1.2 -2.07 2
                  "02012MD05" 2 2  19.90164  1.21  -.23 2
                  "02012NC03" 2 1 13.737705  -.66  -.93 2
                  "02021AG07" 1 2  12.62295   .65  -.57 2
                  "02021AG08" 1 1  12.62295    .8   .53 2
                  "02021AS10" 1 2 19.049181  1.06 -2.03 2
                  "02021AS15" 1 2 10.360656  -.56  -.45 2
                  "02021DN14" 1 1  9.180327  -.91  -.68 2
                  "02021FD06" 1 1 11.311476 -2.79 -1.04 1
                  "02021FT03" 1 2 20.459017   .07 -2.25 2
                  "02021KT02" 1 2 11.409836    .1   -.8 2
                  "02021MD04" 1 2 11.442623   .21   .28 2
                  "02021NB05" 1 2 11.704918   .25  -.25 2
                  "02021ND16" 1 1 17.344263  -.83 -1.78 2
                  "02021OS13" 1 2  10.42623  2.88   -.8 2
                  "02021SD09" 1 2  22.32787   .25  -.71 2
                  "02021YD01" 1 2  9.803279   .59   .05 2
                  "02021YS12" 1 2 10.327868  -.24    .9 2
                  "02022AD11" 2 1  13.90164   -.8  -.77 2
                  "02022AG07" 2 2 12.688524   .29  1.23 2
                  "02022AM05" 2 1 11.934426  1.17  2.15 2
                  "02022AM06" 2 1 13.245902 -1.09  -.96 2
                  "02022CD10" 2 2 13.639344   .52  -.63 2
                  "02022DD15" 2 1 11.704918 -2.66  -.64 1
                  "02022ES01" 2 2 12.983606   .05   .98 2
                  "02022FG12" 2 2 16.393442   -.7  -.46 2
                  "02022FN02" 2 2 17.245901  -.06   .29 2
                  "02022MS03" 2 2 16.819672 -1.99  -.12 2
                  "02022ND08" 2 1 23.016394 -2.18 -2.11 1
                  "02022NH14" 2 2  10.09836 -1.05   .33 2
                  "02022NK09" 2 1 12.557377 -1.74   .33 2
                  "02022SD13" 2 1 11.016394 -2.32 -1.15 1
                  "02022SS04" 2 1 10.065574   .52   .25 2
                  "03011AB01" 1 1 11.868853  1.22  -.18 2
                  "03011AD10" 1 1 18.950819  -.12  -.51 2
                  "03011AG04" 1 2  20.85246 -1.09  -.51 2
                  "03011DB09" 1 2 11.213115   .55  -.66 2
                  "03011DD07" 1 1  12.42623  -.69   .82 2
                  "03011FD08" 1 1  9.836065   1.8  1.28 2
                  "03011HD02" 1 2 18.393442  -.63  -.85 2
                  "03011MD11" 1 2 17.868853 -1.14 -1.05 2
                  "03011MS12" 1 1 16.688524  -.77  -.75 2
                  "03011NK06" 1 2 19.049181 -1.54 -1.53 2
                  "03011OS03" 1 2  11.80328  -.08  -.91 2
                  "03011OS05" 1 2 16.491804 -1.36 -1.42 2
                  "03012AB04" 2 1 21.081966 -1.11   .62 2
                  "03012AD10" 2 1 15.180327 -1.24 -1.39 2
                  "03012AN13" 2 2  20.81967  -.34 -1.46 2
                  "03012AT15" 2 1 23.737705 -1.51   .39 2
                  "03012DD14" 2 1 13.737705 -1.34 -1.52 2
                  "03012FB09" 2 2 13.016394  -.56 -1.08 2
                  "03012FD01" 2 1  15.14754   .49    .6 2
                  "03012FN08" 2 2 19.508196  -.33  -.44 2
                  "03012JN03" 2 1 13.770492  2.09  2.45 2
                  "03012KN06" 2 1 23.344263  -1.2 -1.45 2
                  "03012KS12" 2 1  9.836065  -.11 -1.13 2
                  "03012RB02" 2 2  22.95082 -3.23 -1.96 1
                  "03012RD05" 2 2 18.819672 -2.37  -.46 1
                  "03012SM07" 2 2 15.180327  -.71   .01 2
                  "03012SM11" 2 1 17.049181  -.37  -.55 2
                  "03021AD04" 1 2 11.180327  -.25   .88 2
                  "03021AD14" 1 2 15.540983  -.01 -1.54 2
                  "03021AF06" 1 1  14.85246  -.17   .84 2
                  "03021AN02" 1 1 14.688524  -.99  -.51 2
                  "03021FD09" 1 1 14.655738  -.07  -.66 2
                  "03021FD11" 1 1  13.90164  -.58  -.89 2
                  "03021KN07" 1 2 11.639344   .65  -.58 2
                  "03021MD01" 1 1        20  -.05  -.24 2
                  "03021MS05" 1 2  9.344262  1.12  1.68 2
                  "03021NM03" 1 2  21.27869  -.83 -1.14 2
                  "03021NM08" 1 2 12.032787   .27   .77 2
                  "03021NS13" 1 1 10.983606 -1.94   .73 2
                  "03021RS12" 1 1 10.459017  -.53  2.34 2
                  "03021SS10" 1 1 14.459017 -1.01  -.04 2
                  "03022AD13" 2 2  9.081967  1.16   .52 2
                  "03022AK07" 2 1  9.245902  -2.9   .25 1
                  "03022AS11" 2 1  20.22951  -2.7 -2.13 1
                  "03022CD12" 2 2  20.85246 -2.35 -1.68 1
                  "03022CN02" 2 2 12.590164   .29  -1.2 2
                  "03022KF04" 2 1 12.557377 -1.83 -2.44 2
                  "03022LD06" 2 2 18.885246   .91   .97 2
                  "03022MT03" 2 2  23.90164   .13 -1.25 2
                  "03022ND08" 2 1 14.131147  1.25  -.93 2
                  "03022ND10" 2 2  20.19672  1.02   .19 2
                  "03022NM09" 2 1 12.163935   .38    .1 2
                  "03022NS14" 2 1 10.032787  -.46   .24 2
                  "03022NS15" 2 1 10.032787  -.75    .3 2
                  "03022OB01" 2 2 16.885246   .19  1.31 2
                  "03022ON05" 2 1 13.180327 -1.32  -.93 2
                  "04011AN07" 1 1 18.065575 -2.24 -1.15 1
                  "04011AS15" 1 1 10.819673 -1.06   .05 2
                  "04011AT12" 1 1 12.983606  -.92 -1.03 2
                  "04011AT13" 1 2 14.590164     0  -.33 2
                  "04011BN03" 1 1  11.57377   .38   .58 2
                  "04011DG02" 1 2 12.983606  1.28   .55 2
                  "04011MS01" 1 2  12.09836 -2.11 -2.28 1
                  "04011NF10" 1 2 20.655737 -1.47 -1.27 2
                  "04011NF16" 1 2 13.836065  -.16   .07 2
                  "04011NF17" 1 1 13.836065 -1.18  -.58 2
                  "04011NM05" 1 1 11.639344 -1.34 -2.73 2
                  end
                  
                  //  THIS PART IS YOUR ORIGINAL CODE, UNCHANGED
                  preserve
                  keep if GROUPE == 2
                  rename * *_control
                  rename AGEENFCAL_COR_control age
                  rename SEXENF_control sexe
                  tempfile controls
                  save `controls'
                  list, noobs clean
                  
                  restore
                  keep if GROUPE == 1
                  rename * *_case
                  rename AGEENFCAL_COR_case age
                  rename SEXENF_case sexe
                  
                  rangejoin age -0.25 0.25 using `controls', by(sex)
                  
                  set seed 1234
                  gen double shuffle = runiform()
                  
                  
                  //  THIS IS NEW CODE THAT MAKES ALL CONTROLS ASSOCIATED TO A UNIQUE CASE
                  sort IDENF_case shuffle
                  
                  local i = 1
                  while `i' <= `=_N' {
                      local this_case = IDENF_case[`i']
                      local this_control = IDENF_control[`i']
                      //  DROP ALL OTHER CONTROLS FOR THIS CASE
                      quietly drop if IDENF_case == `"`this_case'"' & _n != `i'
                      //  DROP ALL OTHER OBSERVATIONS USING THIS CONTROL
                      quietly drop if IDENF_control == `"`this_control'"' & _n != `i'
                      local ++i
                  }
                  
                  //    VERIFY NO CONTROL HAS BEEN RE-USED
                  isid IDENF_control, miss
                  In this example, you do not incur any additional unmatched cases from doing this. You may not be so lucky with your full sample. Also, if your data set is large, this will take a long time to run.

                  Comment


                  • #69
                    Thank you very much Clyde,

                    I used your code and the matching was well done. Now, which test would i use to compare proportions between cases and controls? the prtest or the McNemar test (Tables for epidemiologists)?

                    Comment


                    • #70
                      I would use McNemar. But that's just a personal preference.

                      But wait! You said you would be testing nutritional indicators. I'm not sure what variables you have in mind, but the weight and height variables in your example data are continuous variables. So that would call for a paired t-test. If you have dichotomous variables that are nutritional indicators, then my peroneal preference would be to use McNemar, but -prtest var_case =var_control- would be fine, too.

                      All of that said, I am not fond of hypothesis testing anyway. If this were my project, I probably wouldn't do any test. I would instead provide estimates of the difference between the cases and controls on each nutritional indicator (mean of the paired differences) along with confidence intervals.
                      Last edited by Clyde Schechter; 01 Aug 2020, 15:17.

                      Comment


                      • #71
                        Thank you Clyde,

                        I would use pared t test to compare continuous indicators expressed into z-scores and McNemar test to compare binary variables that are recode of the continuous ones. In my case i want to explain the difference between the two groups before matching by the influence of age and sex because when the matching is performed, this difference disappeared.
                        However, i am interested by what you are suggesting and want to try this. How could i calculate the main of the paired difference?

                        Comment


                        • #72
                          Code:
                          gen diff_var = var_control - var_case
                          ci means diff_var

                          Comment


                          • #73
                            Dear Clyde,

                            When performing the McNemar test, i have less than 10 discordant pairs with by data. This is a problem with the application condition of the test. How could i apply a continuity test to take this into account?

                            Thanks

                            Comment


                            • #74
                              I don't know of any continuity correction for the McNemar test. What I was taught to do in that situation is this. You have N1 discordant pairs with case pos and control neg, and N2 discordant pairs with case neg and control pos. (Replace, as appropriate, neg and pos by the two values of whatever attribute you are comparing between the cases and controls.) Under the null hypothesis that the distribution of that attribute is the same in cases and controls, then N1and N2 will each have a binomial distribution with N = N1+N2 and probability parameter 0.5. So, in Stata, -binomial(N1+N2, X, 0.5)-, where X is the smaller of N1 and N2, would give you a one-tailed p-value. Multiply that by two for a two-tailed test.

                              Comment


                              • #75
                                I have 67 cases and 741 controls. I am able to do a 1:1 match following the original instructions listed in this thread matching for age (by using a categorical age group to get past the exact age problem), gender and race.
                                But, I really want to have 2x or 3x the controls for analysis. There a way to have 1:n match using joinby?
                                Thank you in advance

                                preserve
                                keep if CStat_2cat == 0
                                rename * *_control
                                rename agecat_control agecat
                                rename Gender_control gender
                                rename Race_control race
                                tempfile controls
                                save `controls'

                                restore
                                keep if CStat_2cat == 1
                                rename * *_case
                                rename agecat_case agecat
                                rename Gender_case gender
                                rename Race_case race

                                joinby agecat gender race using `controls'
                                set seed 1234 // OR WHATEVER RANDOM NUMBER SEED YOU LIKE
                                gen double shuffle = runiform()
                                by RowLabels_case (shuffle), sort: keep if _n == 1
                                drop shuffle

                                Comment

                                Working...
                                X