Announcement

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

  • group identifier


    Hello everyone,
    I have met a group identifier question but more complicated1) if the age can vary with year,for example in 03/1999 ,age is 20 , next year the age is 20 or 21(no birthday information),how to incorporate the varable age in using egen id =group (age )? a possible method is let the difference of age less than 1 if the pruchasetime is within 1 year,but the group function cannot be used with by or if .(2) if the observations can be classfied into 2 group , the first one is new consumer ,the second one is old consumers ,I need to find the duplicated observations of each observation in group1 from group 2,how to realize in stata?

    puechasetime sexe age location group(new=1)


    28/03/1999 f 31 1 1

    28/06/2000 f 31 2 1

    28/08/2000 f 32 1 2

    05/05/1998 m 39 2 1

    24/06/1999 m 40 2 2

    24/06/1997 m 47 2 2

    Can someone help me ?



    Thank you very much !

  • #2
    Asked and answered at https://www.statalist.org/forums/for...s-observations.

    Comment


    • #3
      Thank you very for your quick reply.
      I think it is really a smart solution! As for the second question:
      If the observations can be classfied into 2 group , the first group is each consumer's first purchase ,the second group is record of consumer's second 、third ...purchase ,I need to find the duplicated observations of each observation in group1 from group 2,how to realize in stata?
      clear
      input byte new_or_old str6 sex int purchasetime byte age
      1 "MALE" 15463 32
      2 "MALE" 15540 31
      1 "MALE" 15589 32
      2 "MALE" 15617 30
      2 "MALE" 15785 31
      2 "MALE" 15862 35
      2 "FEMALE" 15967 30
      1 "MALE" 16051 32
      2 "MALE" 16107 32
      2 "MALE" 16142 35
      2 "FEMALE" 16233 31
      2 "FEMALE" 16471 30
      end
      format %td purchasetime
      [/CODE]

      Thanks again!

      Comment


      • #4
        Assuming the birth year and sex are sufficient information to identify a person:

        Code:
        clear
        input byte new_or_old str6 sex int purchasetime byte age
        1 "MALE" 15463 32
        2 "MALE" 15540 31
        1 "MALE" 15589 32
        2 "MALE" 15617 30
        2 "MALE" 15785 31
        2 "MALE" 15862 35
        2 "FEMALE" 15967 30
        1 "MALE" 16051 32
        2 "MALE" 16107 32
        2 "MALE" 16142 35
        2 "FEMALE" 16233 31
        2 "FEMALE" 16471 30
        end
        format %td purchasetime
        
        gen birth_year = yofd(purchasetime) - age
        
        egen person_id = group(sex birth_year)
        by person_id (purchasetime), sort: gen purchase_num = _n

        Comment


        • #5
          Thanks ! Using
          egen person_id =
          group(sex birth_year),it still possible the new consumers could be classfied into one ID.This is not reasonable for each new consumer is different.Is it possible
          to use group combine with by?

          Comment


          • #6
            How can you tell in the data who is a new consumer?

            -egen, group()- is not compatible with -by-. And if you think about what it does, it would make no sense to use it with -by- even if that were possible.

            Comment


            • #7
              In the data ,there is a record whether the consumer is new or old .

              Comment


              • #8
                Hmm. I see that variable new_or_old. It's coded 1/2 and there is no explanation of whether 1 is new and 2 is old, or the other way around. I[ll assume that 1 is new.

                Code:
                clear
                input byte new_or_old str6 sex int purchasetime byte age
                1 "MALE" 15463 32
                2 "MALE" 15540 31
                1 "MALE" 15589 32
                2 "MALE" 15617 30
                2 "MALE" 15785 31
                2 "MALE" 15862 35
                2 "FEMALE" 15967 30
                1 "MALE" 16051 32
                2 "MALE" 16107 32
                2 "MALE" 16142 35
                2 "FEMALE" 16233 31
                2 "FEMALE" 16471 30
                end
                format %td purchasetime
                
                gen birth_year = yofd(purchasetime) - age
                
                by birth_year sex (purchasetime), sort: gen pnum = sum(new_or_old == 1)
                egen person_id = group(birth_year sex pnum)
                
                by person_id (purchasetime), sort: gen purchase_num = _n
                drop pnum // NOT NEEDED ANY MORE
                The logic behind this code is to find all observations with the same birth year and sex, and arrange them in chronological order of purchase time. Then a series of "old" observations are assumed to be all one person, and whenever a "new" observation is found in the group, we declare a new person.

                I'm not really fond of that logic, because it implies that once a new person comes, the old people with that same sex and birth year never return. If you can justify that based on how the data were collected, then fine. If not, can you think of some other way to distinguish different people among a group of observations with the same birth year and sex?

                Comment


                • #9
                  Hi,everyone,
                  I need to use mixlogit to excuete the random coefficent model,but the data has no choice and group as required by mixlogit.How can I generate these variables based on thechoice brand1-brand4?
                  clear
                  input byte PanID double Expend byte(Income HHSize) int IPT byte(Quantity Brand1 Brand2 Brand3 Brand4 Feature1 Feature2 Feature3 Feature4) double(Price1 Price2 Price3 Price4) byte PanelistFirstObs
                  1 40.900002 9 2 5 2 0 0 0 1 0 0 0 0 .108 .081 .061000001 .079000004 1
                  1 16.809999 9 2 5 2 0 1 0 0 0 0 0 0 .108 .097999997 .064000003 .075000003 0
                  1 4.0599999 9 2 1 2 0 1 0 0 0 0 0 0 .108 .097999997 .061000001 .086000003 0
                  1 34.459999 9 2 4 2 0 1 0 0 0 0 0 0 .108 .097999997 .061000001 .086000003 0
                  1 8.3900003 9 2 7 2 0 1 0 0 0 0 0 0 .125 .097999997 .048999999 .079000004 0
                  1 60.990002 9 2 3 2 0 1 0 0 0 0 0 0 .108 .092 .050000001 .079000004 0
                  1 20.790001 9 2 4 1 0 1 0 0 0 0 0 0 .103 .081 .048999999 .079000004 0
                  1 33.950001 9 2 8 2 0 0 0 1 0 0 0 0 .108 .086000003 .054000001 .079000004 0
                  2 3.6900001 7 2 5 1 1 0 0 0 0 0 0 0 .108 .097999997 .050000001 .079000004 1
                  2 50.93 7 2 2 1 1 0 0 0 0 0 0 0 .108 .097999997 .050000001 .079000004 0
                  2 18.35 7 2 2 1 1 0 0 0 0 0 0 0 .108 .097999997 .050000001 .079000004 0
                  2 31.91 7 2 2 1 1 0 0 0 0 0 0 0 .108 .097999997 .050000001 .079000004 0
                  2 25.27 7 2 2 6 0 0 0 1 0 0 0 0 .108 .081 .050000001 .086000003 0
                  2 35.700001 7 2 2 2 0 0 0 1 0 0 0 0 .108 .081 .050000001 .086000003 0
                  2 30.65 7 2 4 2 0 0 0 1 0 0 0 0 .108 .081 .050000001 .079000004 0
                  2 58.259998 7 2 2 8 0 0 0 1 0 0 0 0 .108 .081 .050000001 .079000004 0
                  2 24.459999 7 2 3 8 0 0 0 1 0 0 0 0 .108 .081 .050000001 .079000004 0
                  2 46.73 7 2 7 6 0 0 0 1 0 0 0 0 .108 .081 .050000001 .079000004 0
                  2 24.43 7 2 3 2 0 0 0 1 0 0 0 0 .108 .081 .050000001 .079000004 0
                  2 16.49 7 2 1 4 0 0 0 1 0 0 0 0 .108 .081 .050000001 .081 0
                  2 4.2600002 7 2 1 4 0 0 0 1 0 0 0 0 .108 .081 .050000001 .079000004 0
                  2 67.230003 7 2 3 2 0 0 0 1 0 0 0 0 .108 .081 .050000001 .079000004 0
                  2 15.14 7 2 1 2 0 0 0 1 0 0 0 0 .108 .081 .050000001 .079000004 0
                  2 27.440001 7 2 5 7 0 0 0 1 0 0 0 0 .108 .081 .050000001 .081 0
                  Thanks a lot!

                  Comment


                  • #10
                    Looks like a new question. Please start a new thread with an informative title.

                    Comment


                    • #11
                      Thanks.I have post a new thread and could you give me answer?

                      Comment

                      Working...
                      X