Announcement

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

  • How to combine multiple observations(in multiple variables) for an individual to one variable?

    Hi Guys

    I'm new here so please forgive me if I didn't create a perfect question.

    My Data looks like this:

    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(o1 o2 o3 id Indep-Var1 Indep-Var2 )
    1 0 1 1 1 0
    0 1 1 2 1 0
    0 1 1 3 1 0
    0 1 1 4 0 1
    0 0 1 5 0 1

    In this example I have 3 observations per subject (o1 o2 o3) and I was wondering how to create a new variable oit (where i is the subject and t is the corresponding number of the observation) so i can create a regression that looks like this:

    reg oit Indep-Var1 Indep-Var2,r


    cheers








    Last edited by Wolfram Ritter; 24 Jul 2017, 07:04.

  • #2
    I'm not sure exactly what you want. You can use bysort id: egen meanx=mean(x) to create means by id while retaining the original number of observations. You can use egen with the count function to give you number of observations per id, or egen with the total function to sum the observations.

    Alternatively, if you want to move to one observation per subject you can use collapse.

    Comment


    • #3
      I also am not completely clear but I think (guess) you want -reshape-:
      Code:
      reshape long o, i(id) j(count)
      or whatever you want your "j" variable to be called

      Comment

      Working...
      X