Announcement

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

  • Keep the value within same ID

    Hello Statalist,

    I I've tried many things and I do not know what to do and ask for help now.

    My datasets are like this:
    ID Year treatment Var3
    1 4 0 ...
    1 5 1 ...
    2 7 0 ...
    2 8 1 ...

    And I would like to classify the treatment with 1 as the group among the IDs whose year is less than 5 years.

    What I mean is that, keep ID 1 and drop ID 2, because treatment year of ID 1 is 5, and ID 2 is 7.
    ID Year treatment Var3
    1 4 0 ...
    1 5 1 ...
    Could you please give me some hints or inspirations


    Thanks in advance.

  • #2
    Your query seems (to me, at least) a bit inconsistent, as the longest treeatment spell for ID 1 is 5 years (not < than 5 years, as per your previous statement).
    Hence, you should be more detailed about what you're after and, please, di use -datex- to post example/excerpt of your data. Thanks.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hello Carlo,
      Thank you for helping me.
      My datasets are kind of panel data, and I want to keep the datagroup, which includes treatment is 1 & period <=5.
      ID period treatment
      34063 22 1
      39725 23 1
      39725 24 1
      39725 25 0
      39725 26 0
      39725 27 0
      39725 28 0
      39880 1 0
      40811 2 0
      40811 3 1
      40811 4 1
      40811 5 1
      40811 6 1
      40811 7 0
      40811 8 0
      41315 1 1
      41315 2 0
      41357 11 0
      41357 12 0
      41357 13 0
      41357 14 0
      41357 15 0
      41357 16 0
      41522 11 0
      41522 12 1
      41522 13 0
      41522 14 0
      41522 15 0
      41522 16 0
      41522 19 0
      42000 3 0
      42000 4 0
      42000 5 1
      42000 6 0
      43494 7 0
      43494 22 0
      43494 23 0
      43494 24 0
      43494 25 1
      43494 26 1
      Therefore my dataset will be as below:
      Groups including treatment before 5 years are only alive.
      ID period treatment
      39880 1 0
      40811 2 0
      40811 3 1
      40811 4 1
      40811 5 1
      40811 6 1
      40811 7 0
      40811 8 0
      41315 1 1
      41315 2 0
      42000 3 0
      42000 4 0
      42000 5 1
      42000 6 0
      Last edited by HS JANG; 26 Jan 2019, 04:36.

      Comment


      • #4
        Thanks in advance. I'd like to use fixed-effects analysis(xtreg) in group with treatment years less than 5 years.

        Comment


        • #5
          There's still something I'm not clear with in your data.
          For instance: id 39880 matches the time criterium (period<=5) but not the treatment one (0 vs 1) (your criteria were: treatment== 1 & period <=5).
          Please, clarify.
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            Hi Carlo,

            I made some mistakes describing my data.
            My criteria were treatment==1 & period<=5. So the ID 39880 should be removed.

            Here are my data that I want to make:

            ID period treatment
            40811 2 0
            40811 3 1
            40811 4 1
            40811 5 1
            40811 6 1
            40811 7 0
            40811 8 0
            41315 1 1
            41315 2 0
            42000 3 0
            42000 4 0
            42000 5 1
            42000 6 0

            Comment


            • #7
              Despite your laudable efforts to make things clearer, you still have weird results in your desired database.
              Be as it may, according to your criteria you should end up with what follows:
              Code:
              . egen flag=group( period treatment) if period<=5 & treatment==1
              
              
              . drop if flag==.
              
              
              . list
              
                   +----------------------------------+
                   |    ID   period   treatm~t   flag |
                   |----------------------------------|
                1. | 40811        3          1      2 |
                2. | 40811        4          1      3 |
                3. | 40811        5          1      4 |
                4. | 41315        1          1      1 |
                5. | 42000        5          1      4 |
                   +----------------------------------+
              Kind regards,
              Carlo
              (Stata 19.0)

              Comment


              • #8
                Dear Carlo,
                It's fantastic! I cannot find that in any books.
                Thank you very much!

                Comment


                • #9
                  You're welcom.
                  It's only a matter of practicing!
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment


                  • #10
                    Previous welcom is welcome.
                    Sorry for the typo.
                    Kind regards,
                    Carlo
                    (Stata 19.0)

                    Comment

                    Working...
                    X