Announcement

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

  • Creating table with unique ID

    Hello,
    I need some help with creating a table. My data has multiple records of the same patients and when I create a table, it put all the multiple entries. I want to put one recordid only one time in the table.

    There are a total of 40 observations, but unique recordid 11. I use the following command to create a demographic table, but it includes all the observations. Is there a way I can only include unique recordid one time only in the table?

    table1, vars(age contn \ gender cat\ serial contn\ base_salary contn\ advance_salary contn\)


    clear
    input float(recordid age) str1 gender float(serial base_salary advance_salary)
    1 45 "f" 1 7400 100
    1 45 "f" 2 7400 200
    1 45 "f" 3 7400 300
    2 27 "f" 4 7400 400
    2 27 "f" 5 7400 500
    3 76 "m" 6 7400 600
    4 19 "f" 7 7400 700
    4 19 "f" 8 7400 800
    4 19 "f" 9 7400 900
    4 19 "f" 10 7400 1000
    4 19 "f" 11 7400 1100
    4 19 "f" 12 7400 1200
    4 19 "f" 13 7400 1300
    5 46 "m" 14 7400 1400
    5 46 "m" 15 7400 1500
    5 46 "m" 16 7400 1600
    5 46 "m" 17 7400 1700
    5 46 "m" 18 7400 1800
    5 46 "m" 19 7400 1900
    5 46 "m" 20 7400 2000
    5 46 "m" 21 7400 2100
    5 46 "m" 22 7400 2200
    5 46 "m" 23 7400 2300
    6 63 "f" 24 7400 2400
    6 63 "f" 25 7400 2500
    7 70 "f" 26 7400 2600
    8 57 "m" 27 7400 2700
    8 57 "m" 28 7400 2800
    8 57 "m" 29 7400 2900
    9 55 "f" 30 7400 3000
    9 55 "f" 31 7400 3100
    9 55 "f" 32 7400 3200
    9 55 "f" 33 7400 3300
    9 55 "f" 34 7400 3400
    10 36 "f" 35 7400 3500
    10 36 "f" 36 7400 3600
    10 36 "f" 37 7400 3700
    10 36 "f" 38 7400 3800
    11 24 "m" 39 7400 3900
    11 24 "m" 40 7400 4000
    12 16 "f" 41 7400 4100
    12 16 "f" 42 7400 4200
    12 16 "f" 43 7400 4300
    12 16 "f" 44 7400 4400
    12 16 "f" 45 7400 4500
    12 16 "f" 46 7400 4600
    13 61 "m" 47 7400 4700
    13 61 "m" 48 7400 4800
    13 61 "m" 49 7400 4900
    13 61 "m" 50 7400 5000
    13 61 "m" 51 7400 5100
    14 28 "f" 52 7400 5200
    14 28 "f" 53 7400 5300
    14 28 "f" 54 7400 5400
    14 28 "f" 55 7400 5500
    15 12 "m" 56 7400 5600
    16 35 "f" 57 7400 5700
    16 35 "f" 58 7400 5800
    16 35 "f" 59 7400 5900
    16 35 "f" 60 7400 6000
    17 28 "m" 61 7400 6100
    17 28 "m" 62 7400 6200
    18 89 "f" 63 7400 6300
    18 89 "f" 64 7400 6400
    18 89 "f" 65 7400 6500
    18 89 "f" 66 7400 6600
    18 89 "f" 67 7400 6700
    19 21 "m" 68 7400 6800
    19 21 "m" 69 7400 6900
    20 49 "f" 70 7400 7000
    20 49 "f" 71 7400 7100
    20 49 "f" 72 7400 7200
    20 49 "f" 73 7400 7300
    20 49 "f" 74 7400 7400
    end

  • #2
    You are using some unexplained command table1, so I think that needs to be explained as the solution will depend on what it does.

    Comment


    • #3
      table1 -- Create "table 1" of baseline characteristics for a manuscript

      Syntax

      table1 [if] [in] [weight], vars(var_spec) [options]

      var_spec = varname vartype [varformat] [ \ varname vartype [varformat] \ ...]

      Supported variable types:
      contn - continuous, normally distributed
      conts - continuous, skew
      cat - categorical, groups compared using Pearson's chi-squared
      cate - categorical, groups compared using Fisher's exact test
      bin - binary, groups compared using Pearson's chi-squared
      bine - binary, groups compared using Fisher's exact test

      Comment


      • #4
        note that there is an "updated" version called -table1_mc" also available at SSC

        either command takes "if" (or "in") conditions as you show in what you apparently copied from the help file - so why not use "if recordid==11" as part of your command?

        Comment


        • #5
          Thanks, but it is not just one recordid 11, There are multiple entries for each recordid, and I want Stata to count only one time each recordid while constructing the table1

          Comment


          • #6
            Table1, as per help files, accepts the ‘if’ condition, hence we may create a tag with - egen -, then use ‘if tag’ for table1.
            Best regards,

            Marcos

            Comment


            • #7
              I am sorry to ask again, I am new to using stata. Can you please write the cord with this egen and using if tag for table one? My dataex data is above for your quick reference. I will truly appreciate your kind help.

              Thanks

              Comment


              • #8
                Just type - help egen - in the command window. Then, please read the option with tag(). After that, use table1 plus the condition - if tag ==1.

                Please read the FAQ. There you’ll find how to share data/command/output in this Forum.
                Best regards,

                Marcos

                Comment


                • #9
                  In #1, "advance_salary" varies over observations. Therefore, these are not simpy duplicate observations. The question is what kind of summary statistic are you looking for - mean, sum or something else?

                  Comment

                  Working...
                  X