Announcement

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

  • How to browse data with complicated condition

    I have firm-level data for 2010-2015. I would like to browse variable output and capital for specific firmcode that has zero capital in 2010. I tried to do this in STATA with the following command:

    br firmcode if capital==0 & year==2010

    Then I got the list of 2966 specified firmcodes, such as 71, 133, 155, etc. In order to correct zero capital in 2010 by inputing the capital value in the following year and by assuming no investment in 2010, so I need to browse those firmcodes by using the following command:

    br year firmcode output capital inv inv2 if firmcode==71|firmcode==133|firmcode==155|firmcode= =502|firmcode==534|firmcode==747|firmcode==853|fir mcode==1335|firmcode==1346|
    firmcode==1349|firmcode==1352|firmcode==1583|firmc ode==1646|firmcode==1647|firmcode==1658|firmcode== 1660|firmcode==1712|firmcode==1724|firmcode==1774| firmcode==1797|firmcode==1941|firmcode==1948|firmc ode==1951|firmcode==1987

    As the firmcodes with zero capital in 2010 are 2966, it will take alot of time if I do by this method. I have to browse many times. Is there another way to browse the specified condition without writing down all he firmcodes?

  • #2
    You describe your objective as, if I understand it correctly, copying the value of capital from 2011 to 2010 if the value in 2010 is zero. You don't need to type that in yourself in the data edtior, instead let Stata do the copying.
    Code:
    bysort firmcode (year): replace capital = capital[_n+1] if capital==0 & year==2010 and year[_n+1]==2011
    To answer the question you asked, how to browse the firms for which capital was zero in the year 2010, for a complicated condition it's easiest to construct a simple indicator variable that is 1 for the observations you want to browse and 0 for the others. In your case, the code might look like the following.
    Code:
    bysort firmcode (year): cap2010 = max(capital==0 & year==2010)
    browse year firmcode output capital inv inv2 if cap2010==1
    And since you only need to look at 2010 and 2011 to copy 2011 to 2010
    Code:
    bysort firmcode (year): cap2010 = max(capital==0 & year==2010)
    replace cap2010 = 0 if ! inlist(year,2010,2011)
    browse year firmcode output capital inv inv2 if cap2010==1
    Finally, if your objective was to edit the data, you will want to use the edit command rather than the browse command.

    Comment


    • #3
      Hi William Lisowski,

      Thank you very much for your reply. I am really grateful for your help. For the first code, it worked well replacing zero capital in 2010 by capital in 2011. I tried the second command but I got message as follows:

      command cap2010 is unrecognized
      r(199);

      would you please to explain what I should do to correct the code?

      Comment


      • #4
        I am sorry, I left out the command. I must have thought I was writing SAS instead of Stata. Here is corrected code. Thank you for letting me know: I wouldn't want to have a mistake hanging around to trap someone months from now.
        Code:
        bysort firmcode (year): generate cap2010 = max(capital==0 & year==2010)
        replace cap2010 = 0 if ! inlist(year,2010,2011)
        browse year firmcode output capital inv inv2 if cap2010==1

        Comment


        • #5
          I tried again with the corrected command, but it still gave me error message as follow:

          bysort firmcode (year): gen cap2010 = max(capital==0 & year==2010)
          invalid syntax
          r(198);

          Comment


          • #6
            Today is not a good day for me. This is what happens when I don't have data to test with.
            Code:
            bysort firmcode (year): egen cap2010 = max(capital==0 & year==2010)
            replace cap2010 = 0 if ! inlist(year,2010,2011)
            browse year firmcode output capital inv inv2 if cap2010==1

            Comment

            Working...
            X