Announcement

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

  • Is there a way to list the observations that share a particular set of values for one variable?

    Hello everyone,

    [EDIT: I just realize that's not how people have been posting code - please bear with me as I try to fix that.]

    Thank you all - I appreciate your patience with me as I stumble through using this program.

    My data has a bunch of cases and controls that are matched (at a ratio of 1:10) by the variable 'matchgroup', and this variable matchgroup goes up to about 13,000. I have ~1200 cases and I need to pick out their respective controls. The cases are indicated in a dummy variable I named 'omitted_cases.' Is there a way I can generate another dummy variable for the respective controls?
    My method so far has been something along the lines of:
    Code:
    gen dummy_variable = 0
    replace dummy_variable = 1 if inlist(matchgroup, 1, 2, 3, 4)
    And I manually enter the matchgroup values for the cases that I'm interested in. My issue is this time I have about 1000 matchgroup values to enter, and I can't possibly sit there and list them all manually.
    Is there a better way to do this?

    Thank you so much for your help,

    Jon
    Last edited by Johnathan Athanasius; 02 Jun 2022, 17:34.

  • #2
    You have left out the most important information needed to solve this problem: how do you know, for any given case, which values of match_group are the ones for that case's controls.

    It will also be very helpful you post a short excerpt of your data that includes a few cases and their matched controls. Be sure to use the -dataex- command to do that. If you are running version 17, 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
      Hi Clyde,

      I'm not sure I can use dataex the way it was intended. My dataset is set up on a HIPAA compliant server, and I'm blocked from copy and pasting anything outside of the server.
      I used the dataex command and manually created this table that looks like what got outputted:
      ID subject_type matchgroup omitted_cases
      1 case 1 1
      2 control 1 0
      3 control 1 0
      4 case 2 0
      5 control 2 0
      6 control 2 0
      7 case 3 0
      8 control 3 0
      9 control 3 0
      10 case 4 1
      11 control 4 0
      12 control 4 0
      This is how I've been picking out matchgroup values:

      Code:
       br matchgroup if omitted_cases == 1
      And then I highlight the matchgroup column and paste the values into a do-file, and from there I move all the numbers into one line and separate them by , so that I can do inlist(matchgroup, 1, 2, 3). But this time, it's like 1300 values and I hope there is a better way.

      Thank you,
      Jon

      Comment


      • #4
        I'm sorry, but I don't have the foggiest notion of how this is supposed to work. Why don't you hand work what the results should look like for the tableau you showed in #3 and post back with that. I don't understand your explanation of the method at all. Maybe if I can see what is supposed to go with what, I can understand what you want.

        Comment

        Working...
        X