Announcement

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

  • variable not found

    Dear Statalisters,

    I was doing a simple lag operation for my panel data (data set name: HAVE)

    sort gvkey year
    gen L_issue=L.issue

    error : variable gvkeyn not found

    in my data, I have gvkey (long format), it is a unique firm identifier, gvkeyn was a str variable in my earlier dataset, after combining multiple data sources, I finally obtained dataset HAVE. I did not keep gvkeyn.

    my question is : why stata is still asking for gvkeyn, is it somehow tied to my current data? Have you ever run into similar situations ?

    Best,

    Rochelle

  • #2
    well, if you discarded gvkey, then attempt to sort by it, your error is quite normal and expected. Or am I missing something?

    Comment


    • #3
      Hi Ben,
      I discard gvkeyn , not gvkey, and the sort step produces no error.

      -R

      Comment


      • #4
        Are the data xtset with gvkeyn? That might cause the problem, e.g.

        Code:
        . use http://www.stata-press.com/data/r13/nlswork.dta, clear
        (National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
        
        . xtset
               panel variable:  idcode (unbalanced)
                time variable:  year, 68 to 88, but with gaps
                        delta:  1 unit
        
        . drop idcode
        
        . sort grade
        
        . gen L_race=L.race
        variable idcode not found
        r(111);
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          ". . . gvkeyn was a str variable in my earlier dataset, after combining multiple data sources, I finally obtained dataset HAVE. I did not keep gvkeyn."

          You haven't shown us all of your code, but I'm guessing that somewhere along the way (in the part of the code that you don't show), you did something like tsset gvkeyn year when it was numeric and not string. The code below reproduces the code that you do show and also reproduces the error that you get. Such a way might exist, but I'm not aware of any other way to get that error with the code that you do show.

          .ÿversionÿ13.1

          .ÿ
          .ÿclearÿ*

          .ÿsetÿmoreÿoff

          .ÿsetÿseedÿ`=date("2014-06-27",ÿ"YMD")'

          .ÿ
          .ÿquietlyÿsetÿobsÿ25

          .ÿgenerateÿstrÿgvkeynÿ=ÿstring(floor(10e6ÿ*ÿruniform()))

          .ÿisidÿgvkeyn

          .ÿ
          .ÿquietlyÿexpandÿ10

          .ÿbysortÿgvkeyn:ÿgenerateÿintÿyearÿ=ÿ2000ÿ+ÿ_n

          .ÿ
          .ÿgenerateÿdoubleÿissueÿ=ÿruniform()

          .ÿ
          .ÿ*
          .ÿ*ÿBeginÿhere
          .ÿ*
          .ÿrenameÿgvkeynÿgvkey

          .ÿquietlyÿdestringÿgvkey,ÿgenerate(gvkeyn)

          .ÿ
          .ÿtssetÿgvkeynÿyear
          ÿÿÿÿÿÿÿpanelÿvariable:ÿÿgvkeynÿ(stronglyÿbalanced)
          ÿÿÿÿÿÿÿÿtimeÿvariable:ÿÿyear,ÿ2001ÿtoÿ2010
          ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿdelta:ÿÿ1ÿunit

          .ÿdropÿgvkeyn

          .ÿquietlyÿdestringÿgvkey,ÿreplace

          .ÿ
          .ÿsortÿgvkeyÿyear

          .ÿgenerateÿdoubleÿL_issueÿ=ÿL.issue
          variableÿgvkeynÿnotÿfound
          r(111);

          endÿofÿdo-file

          r(111);

          .

          Comment


          • #6
            Assuming that either Joe or I are right, you just need to redo or undo the xtset or tsset command. I am guessing you want

            xtset gvkey year
            -------------------------------------------
            Richard Williams, Notre Dame Dept of Sociology
            StataNow Version: 19.5 MP (2 processor)

            EMAIL: [email protected]
            WWW: https://www3.nd.edu/~rwilliam

            Comment


            • #7
              Huh, it sure takes a long time for posts to appear. When I posted my 11:50, your 11:39 wasn't there (wasn't visible to me). If I had seen it, I wouldn't have bothered posting mine.

              Comment


              • #8
                OK, sorry for my misunderstanding. You seem to have previously tsset by gvkeyn. So tsset by gvkey?

                tsset, clear
                tsset gvkey year
                Last edited by ben earnhart; 26 Jun 2014, 20:35. Reason: Fixed "tsset, clear" command

                Comment


                • #9
                  Originally posted by Joseph Coveney View Post
                  Huh, it sure takes a long time for posts to appear. When I posted my 11:50, your 11:39 wasn't there (wasn't visible to me). If I had seen it, I wouldn't have bothered posting mine.
                  That has happened to me several times too! I am not sure if it is because the post hasn't appeared, or if it is because I haven't refreshed my browser in a long time. I suppose if it takes a few minutes to compose an answer others could sneak in ahead of you.
                  -------------------------------------------
                  Richard Williams, Notre Dame Dept of Sociology
                  StataNow Version: 19.5 MP (2 processor)

                  EMAIL: [email protected]
                  WWW: https://www3.nd.edu/~rwilliam

                  Comment


                  • #10
                    And, I didn't see the posts by Coveney or Williams while I was posting/editing. Huh.

                    Comment


                    • #11
                      Immediately after I posted mine, I took a look to make sure that the formatting was okay, and at the moment there was nothing in between Rochelle's 11:24 post and mine. I'd noticed this in the past, and I've tried refreshing the browser, but it didn't seem to make any difference.

                      My guess is that it's a proxy server kind of phenomenon, and that Ben and I are posting to the thread on our respective proxy servers--we see only what's on that local server until it gets re-synchronized every 10 minutes or whatever.

                      Comment


                      • #12
                        Ben's tsset post somehow snuck in right before one of mine without me seeing it until now. I suppose if it was just a matter of refreshing the browser you would notice someone else had joined in. Most peculiar. I don't think I have seen behavior like this before on any other forum I have been on.
                        -------------------------------------------
                        Richard Williams, Notre Dame Dept of Sociology
                        StataNow Version: 19.5 MP (2 processor)

                        EMAIL: [email protected]
                        WWW: https://www3.nd.edu/~rwilliam

                        Comment


                        • #13
                          Hi, Joseph, Richard, and Ben

                          Thanks very much for your posts !!!! You might notice in my original post , I only did sort, not xtset , or tsset . After I follow your suggestions, the problem went away.

                          thanks again

                          Rochelle

                          Comment

                          Working...
                          X