Announcement

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

  • Copy value for a group

    Hey everybody,

    I have a dataset with funds and fund families. 2-7 funds belong to 1 fund families,

    First, I have to compute deciles (dens_perc) for the fund families at each time point.

    In the second step, I want to copy the deciles to every fund of the fund family at each time point.

    mgmtquarter is a identifier for each fund family and time point (egen mgmtquarter = group (fund time)).

    I found that command:
    Syntax: bysort mgmtquarter(dens_perc): replace dens_perc = dens_perc[1]

    But I got the error message:
    factor variables and time-series operators not allowed
    r(101);

    Thank you for your advices

    Best wishes

  • #2
    You need a blank space between mgmtquarter and (dens_perc). The error message is, admittedly, not very informative. It's Stata's syntax parser's best guess as to what you were doing wrong--but not a very good guess in this case.

    Comment


    • #3
      Is there also a possiblity to adjust the code: bysort mgmtquarter (dens_perc): replace dens_perc = dens_perc[1].

      Every observation in my group has a value, no missing values.

      But I always want to replace all observations of the group with the seventh oberservation.
      So, I need to replace all values of the group with the value of exact one observation.


      Any suggestions?

      Right now, I set all values - except the one I need - equal to zero and then create a new variable like: bysort id_group: egen value = max (old_group)
      But this is not very intuitive...

      Comment


      • #4
        You can use 7 as a subscript just as you used 1. Clearly, observations must be in the desired sort order.

        Comment


        • #5
          I tried it. But the problem is id_group is not sufficient to sort the data correctly.

          I need to sort the data with id_group_time and then replace the observation within id_group with my seventh observation...

          So, I have to sort the data at first and the add the "by" function within one command.

          I tried something like: sort id_group_time: egen value = max (old_group), by id_group. But that is wrong!
          Last edited by Bene Eil; 01 Nov 2015, 06:25.

          Comment


          • #6
            Your example code, defining a maximum, bears no apparent relation to your question about using the 7th value.

            You may want something like

            Code:
            bysort idgroup (time) : gen whatever2 = whatever[7]
            Note that I am using generate here. Using replace when you are not clear what code you should be using is likely just to mess up your dataset.

            Please do read http://www.statalist.org/forums/help for advising on showing data examples, the code you actually used, etc., etc.
            Last edited by Nick Cox; 01 Nov 2015, 07:19.

            Comment

            Working...
            X