Announcement

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

  • variable id not found r(111)


    Can anyone tell me the proglem in the second statement. When I apply the first statement it went fine the purpose is to take the mean value of capx for all built=1 But second statement gives an error.
    gen all = 1

    table all if built == 1, c(mean capx) format(%9.2f)
    Code:
      table all if F.built == 1 & built == 0, c(mean capx) format(%9.2f)
    
    variable id not found
    r(111);
    Last edited by Jahan zee; 06 Aug 2017, 09:57.

  • #2
    You don't provide any example data, so it isn't possible to determine if something peculiar in your data is causing this. Suffice it to say that I've tried this code out using the built-in auto.dta and modifying the code to use variable names in that set and cannot reproduce your problem.

    Note also that your code is just an overly complicated way of running:
    Code:
    tabstat /* or, for that matter, summ*/ capx if F.built == 1 & built == 0, format(%9.2f)
    You don't need the device of variable all here.

    Anyway, I'll make a stab in the dark here and guess that this error message arises because at some point in building up the data set it needs for your -table- command Stata finds an empty data set. Try this:

    Code:
    summ capx if F.built == 1 & built == 0
    If the answer is 0 observations, then I think that's the root of the problem: you're trying to calculate the mean of an empty set of values, and -table- chokes on that.

    Comment


    • #3
      Thank you sir for your advice.
      Here purpose is to calculate the mean (capx) value where built=1 [already calculated].
      Now required: Calculating mean for the same company(cusip) 1 year before where built=1 and 1 year after
      before (mean) mean built=1 After (Mean)
      This is calculated

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input double fyear str10 cusip float built double capx
      1989 "666499207" 0   3.402
      1989 "398629204" 0   3.174
      1989 "385006101" 0  12.014
      1989 "090915109" 0   5.087
      1989 "449842103" 0  18.196
      1989 "244878203" 0    15.4
      1989 "170032809" 0 111.928
      1989 "914272109" 0    .001
      1989 "256603101" 0 303.906
      1989 "016230104" 0   9.719
      1989 "628452104" 0     .55
      1989 "570279109" 0    .136
      1989 "871371100" 0   2.702
      1989 "723686101" 0  95.952
      1989 "755078102" 0  13.446
      1989 "129598108" 0   2.129
      1989 "209885102" 0       0
      1989 "233236108" 0    .753
      1989 "028689107" 0   1.568
      1989 "879080109" 0    .904
      1990 "755078102" 0  14.601
      1990 "170032809" 1 282.475
      1990 "244878203" 0    15.7
      1990 "879080109" 0   1.371
      1990 "570279109" 0    .058
      1990 "016230104" 0  11.649
      1990 "628452104" 1   2.546
      1990 "209885102" 0       0
      1990 "871371100" 0   8.023
      1990 "090915109" 0       .
      1990 "723686101" 0  73.667
      1990 "398629204" 0   3.925
      1990 "385006101" 0  10.671
      1990 "233236108" 0    .621
      1990 "129598108" 0   2.604
      1990 "256603101" 0 246.527
      1990 "449842103" 0  21.728
      1990 "568247100" 0   1.164
      1990 "666499207" 0   6.978
      1990 "028689107" 0    1.51
      1991 "233236108" 0    .376
      1991 "568247100" 0    .492
      1991 "570279109" 1    .001
      1991 "15745J205" 0   1.482
      1991 "244878203" 0    15.5
      1991 "090915109" 0       .
      1991 "666499207" 0   3.722
      1991 "016230104" 0   12.93
      1991 "170032809" 0  355.16
      1991 "755078102" 0  13.725
      1991 "209885102" 0       0
      1991 "879080109" 0    .902
      1991 "449842103" 0   17.89
      1991 "129598108" 0   1.464
      1991 "723686101" 0  51.229
      1991 "256603101" 0  325.16
      1991 "628452104" 0   5.804
      1991 "398629204" 0   3.775
      1991 "871371100" 0   4.185
      1992 "879080109" 0   1.285
      1992 "129598108" 0   1.461
      1992 "568247100" 0   1.792
      1992 "449842103" 0  38.548
      1992 "628452104" 0    2.09
      1992 "233236108" 0   1.039
      1992 "247357106" 0     4.5
      1992 "755078102" 0   14.02
      1992 "666499207" 0   6.461
      1992 "170032809" 0  409.77
      1992 "256603101" 1 204.923
      1992 "398629204" 0   5.184
      1992 "871371100" 0   7.751
      1992 "209885102" 0       0
      1992 "016230104" 0   7.993
      1992 "723686101" 0  74.853
      1992 "15745J205" 0   3.949
      1992 "244878203" 0    21.3
      1993 "233236108" 0    .331
      1993 "170032809" 0 196.554
      1993 "244878203" 0    15.9
      1993 "209885102" 0   2.838
      1993 "247357106" 0   2.342
      1993 "449842103" 0  53.741
      1993 "871371100" 0    3.56
      1993 "879080109" 1   1.441
      1993 "628452104" 0   5.765
      1993 "129598108" 0   4.607
      1993 "755078102" 0  13.353
      1993 "723686101" 1  99.926
      1993 "398629204" 0    2.98
      1993 "090915109" 0       .
      1993 "15745J205" 0   4.862
      1993 "016230104" 0   7.626
      1993 "256603101" 0 218.659
      1993 "G36738105" 0    14.9
      1993 "740577101" 0     .96
      1993 "666499207" 0  10.587
      1993 "568247100" 0   4.742
      1994 "398629204" 0   7.165
      1994 "209885102" 0       0
      end

      Comment


      • #4
        Same problem after running this code. I have added the example dataset here.
        Originally posted by Clyde Schechter View Post
        Code:
        summ capx if F.built == 1 & built == 0

        Comment


        • #5
          Thanks for posting the example. I am unable to reproduce the problem:
          Code:
          . * Example generated by -dataex-. To install: ssc install dataex
          . clear
          
          . input double fyear str10 cusip float built double capx
          
                    fyear       cusip      built        capx
            1. 1989 "666499207" 0   3.402
            2. 1989 "398629204" 0   3.174
            3. 1989 "385006101" 0  12.014
            4. 1989 "090915109" 0   5.087
            5. 1989 "449842103" 0  18.196
            6. 1989 "244878203" 0    15.4
            7. 1989 "170032809" 0 111.928
            8. 1989 "914272109" 0    .001
            9. 1989 "256603101" 0 303.906
           10. 1989 "016230104" 0   9.719
           11. 1989 "628452104" 0     .55
           12. 1989 "570279109" 0    .136
           13. 1989 "871371100" 0   2.702
           14. 1989 "723686101" 0  95.952
           15. 1989 "755078102" 0  13.446
           16. 1989 "129598108" 0   2.129
           17. 1989 "209885102" 0       0
           18. 1989 "233236108" 0    .753
           19. 1989 "028689107" 0   1.568
           20. 1989 "879080109" 0    .904
           21. 1990 "755078102" 0  14.601
           22. 1990 "170032809" 1 282.475
           23. 1990 "244878203" 0    15.7
           24. 1990 "879080109" 0   1.371
           25. 1990 "570279109" 0    .058
           26. 1990 "016230104" 0  11.649
           27. 1990 "628452104" 1   2.546
           28. 1990 "209885102" 0       0
           29. 1990 "871371100" 0   8.023
           30. 1990 "090915109" 0       .
           31. 1990 "723686101" 0  73.667
           32. 1990 "398629204" 0   3.925
           33. 1990 "385006101" 0  10.671
           34. 1990 "233236108" 0    .621
           35. 1990 "129598108" 0   2.604
           36. 1990 "256603101" 0 246.527
           37. 1990 "449842103" 0  21.728
           38. 1990 "568247100" 0   1.164
           39. 1990 "666499207" 0   6.978
           40. 1990 "028689107" 0    1.51
           41. 1991 "233236108" 0    .376
           42. 1991 "568247100" 0    .492
           43. 1991 "570279109" 1    .001
           44. 1991 "15745J205" 0   1.482
           45. 1991 "244878203" 0    15.5
           46. 1991 "090915109" 0       .
           47. 1991 "666499207" 0   3.722
           48. 1991 "016230104" 0   12.93
           49. 1991 "170032809" 0  355.16
           50. 1991 "755078102" 0  13.725
           51. 1991 "209885102" 0       0
           52. 1991 "879080109" 0    .902
           53. 1991 "449842103" 0   17.89
           54. 1991 "129598108" 0   1.464
           55. 1991 "723686101" 0  51.229
           56. 1991 "256603101" 0  325.16
           57. 1991 "628452104" 0   5.804
           58. 1991 "398629204" 0   3.775
           59. 1991 "871371100" 0   4.185
           60. 1992 "879080109" 0   1.285
           61. 1992 "129598108" 0   1.461
           62. 1992 "568247100" 0   1.792
           63. 1992 "449842103" 0  38.548
           64. 1992 "628452104" 0    2.09
           65. 1992 "233236108" 0   1.039
           66. 1992 "247357106" 0     4.5
           67. 1992 "755078102" 0   14.02
           68. 1992 "666499207" 0   6.461
           69. 1992 "170032809" 0  409.77
           70. 1992 "256603101" 1 204.923
           71. 1992 "398629204" 0   5.184
           72. 1992 "871371100" 0   7.751
           73. 1992 "209885102" 0       0
           74. 1992 "016230104" 0   7.993
           75. 1992 "723686101" 0  74.853
           76. 1992 "15745J205" 0   3.949
           77. 1992 "244878203" 0    21.3
           78. 1993 "233236108" 0    .331
           79. 1993 "170032809" 0 196.554
           80. 1993 "244878203" 0    15.9
           81. 1993 "209885102" 0   2.838
           82. 1993 "247357106" 0   2.342
           83. 1993 "449842103" 0  53.741
           84. 1993 "871371100" 0    3.56
           85. 1993 "879080109" 1   1.441
           86. 1993 "628452104" 0   5.765
           87. 1993 "129598108" 0   4.607
           88. 1993 "755078102" 0  13.353
           89. 1993 "723686101" 1  99.926
           90. 1993 "398629204" 0    2.98
           91. 1993 "090915109" 0       .
           92. 1993 "15745J205" 0   4.862
           93. 1993 "016230104" 0   7.626
           94. 1993 "256603101" 0 218.659
           95. 1993 "G36738105" 0    14.9
           96. 1993 "740577101" 0     .96
           97. 1993 "666499207" 0  10.587
           98. 1993 "568247100" 0   4.742
           99. 1994 "398629204" 0   7.165
          100. 1994 "209885102" 0       0
          101. end
          
          . egen cusip_group = group(cusip)
          
          . xtset cusip_group fyear
                 panel variable:  cusip_group (unbalanced)
                  time variable:  fyear, 1989 to 1994, but with a gap
                          delta:  1 unit
          
          . summ capx if F.built == 1 & built == 0
          
              Variable |        Obs        Mean    Std. Dev.       Min        Max
          -------------+---------------------------------------------------------
                  capx |          6      85.639    126.3785       .058     325.16
          
          . 
          . gen all = 1
          
          . table all if F.built == 1 & built == 0, c(mean capx) format(%9.2f)
          
          ----------------------
                all | mean(capx)
          ----------+-----------
                  1 |      85.64
          ----------------------
          Suggestions. Exit Stata, re-launch and try again. If that does not work, reboot your computer and try again. If that does not work, reinstall Stata and try again. If that does not work, I think you will need to contact technical support.

          Comment


          • #6
            Two comments.

            1) Perhaps Jahan Zee will find help with the new question that opens post #3 above in the response to Jahan dgk's identical question using the same data, posted at https://www.statalist.org/forums/for...st-event-years

            2) After reading in the sample data from post #3 I can reproduce the type of problem reported in post #1 - lack of a variable named "id" in a command that makes no reference to the variable "id" - in the following way.
            Code:
            . encode cusip, generate(id)
            
            . xtset id fyear
                   panel variable:  id (unbalanced)
                    time variable:  fyear, 1989 to 1994, but with a gap
                            delta:  1 unit
            
            . drop id
            
            . summ capx if F.built == 1 & built == 0
            variable id not found
            r(111);

            Comment

            Working...
            X