Announcement

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

  • Drop panel

    Hey guys,

    I am struggling a bit with dropping a whole panel if a condition is met.

    I have a unique ID and time variables showing development of ID over time and i am trying to do panel survival analysis using xtstreg. First, however, I need to remove all observations relating to ID's with a specific characteristic. I have used the following commands:

    gen flag=0
    replace flag if (my set of criteria)
    drop if flag(_N)==1

    as i understood from previous discussions stata should decode that all obs in the panel need to be deleted if at least one violated my set of conditions by including (_N) in the command, but it returns following error:

    factor-variable and time-series operators are not allowed.

    Can anyone advice on how to eliminate this errror?

  • #2
    Jana:
    welcome to the list.
    As you don't provide the -set of your criteria- I find difficult to reply positively.
    That said (and for what it worths) the last line of your code need square brackets around -_N- to work as expected.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you for your reply Carlo. Regarding the conditions i have generated a variable flag, which is =1 if it does not meet 3 conditions such as date1-date2>0 etc. But i am confident that variable is correctly generated and in data editor i observe that it flags all observations i expect it to.

      Then i would like to tell STATA delete each ID for which over the observed time (60 obs per ID on avg) it flagged at least one, but i am currently unable to.

      I replaced the correct brackets as you suggested, but still get the following error:

      drop id[_N] if flag==1

      weights not allowed

      I would be thankful for any suggestions.

      Regards,

      Jana

      Comment


      • #4
        Jana,

        Honestly, your description is not clear enough for me to catch exactly your problem. But if I might be correct in understanding it, you should try:
        Code:
        sort ID flag
        bysort ID: gen flagtest=flag[_N]
        drop if flagtest==1
        Regards,

        Romalpa
        Last edited by Romalpa Akzo; 17 Oct 2017, 06:14.

        Comment


        • #5
          Jana:
          a broader issue rests on the correctness of dropping a panel with given characteristics, as you may end with a sort of "made-up" subsample of the original one.
          Kind regards,
          Carlo
          (Stata 19.0)

          Comment


          • #6
            The error message in post #3 is because the syntax is incorrect.

            The drop command will drop a variable from the dataset when given a variable name
            Code:
            drop id
            which is not what is wanted here, or will use the if or in qualifiers to drop observations from the dataset
            Code:
            bysort ID (flag): drop if flag[_N]==1
            which will drop every value for a given ID if the largest value of flag for that ID is 1.

            In post #3, id is a variable name, and then Stata saw the left bracket, which is not part of the variable name, and incorrectly guessed that a weight was being specified, whereas you meant it as a subscript - neither of which is allowed in the drop command. So Stata reported a syntax error, but guessed wrong about what the error was.

            Comment


            • #7
              Thank you all for your replies. I have obtained a raw dataset which includes data irrelevant to my analysis, so i will not skew the results by omitting them, just the party responsible for data export was not clear on what is relevant for my research. Thank you for the syntax correction.

              Comment

              Working...
              X