Announcement

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

  • Test

    Dear Statalist,

    I am working with panel data where firms (gvkey) have several segments (Ind_j_NAICS) in different years (yr).

    Looking at the example below, I want to loop through all the the firm-years (2000-20002) and change to “missing” all the Red_orig#### that do not appear among the Ind_j_NAICS. In other words, I want to compare which Ind_j_NAICS are listet per firm and per firm-year to the following Red_orig#### variables.

    For the first observation I want Stata to change to "missing" the Red_orig3324 Red_orig3352 Red_orig3364 Red_orig5120 Red_orig5131 Red_orig5133 variables because the last four digits of these variables are not among the Ind_j_NAICS in year 2000 for firm 005047.

    How should I tackle this issue?
    Many thanks for your help!

    Best,

    Teresa

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str6 gvkey float yr str4 Ind_j_NAICS double(Red_orig3252 Red_orig3260 Red_orig3324 Red_orig3334 Red_orig3336 Red_orig3344 Red_orig3345 Red_orig3351 Red_orig3352 Red_orig3364 Red_orig5120 Red_orig5131 Red_orig5133)
    "005047" 2000 "3252"        . .9975759  .964081 .9803877 .9806081  .992728 .9929483 .9316878 .9347729 .9969148  .592772  .583076 .7384309
    "005047" 2000 "3260" .7274722        . .7226544 .9944162 .7252822 .9984675  .997701 .9813863  .985985 .9991245 .2931133 .2781126  .392314
    "005047" 2000 "3334" .9352504 .9455278 .9814993        . .9835547 .9424446 .9938321 .9804717 .9825272  .997943 .4994849 .4665972 .6783132
    "005047" 2000 "3336" .9718416 .9718416 .9967813 .9959768        . .9710371 .9983903 .9814958 .9871273 .9991948 .4987927 .4794847 .6822199
    "005047" 2000 "3344"  .616863 .6223283 .6079585 .6163103 .6150208        . .9990785 .6039669  .608634 .6225125 .3831979 .3574059 .4824979
    "005047" 2000 "3345" .9737095 .9777689 .9884012 .9860815  .990721 .9783488        . .9847283  .987048 .9990331 .6081576 .5917261 .8641017
    "005047" 2000 "3351" .9229289 .9421967 .9826592 .9961466 .9788056 .9383431 .9942198        . .9980734 .9980734  .578035 .5452796 .7032757
    "005047" 2001 "3252"        . .9975759  .964081 .9803877 .9806081  .992728 .9929483 .9316878 .9347729 .9969148  .592772  .583076 .7384309
    "005047" 2001 "3260" .7274722        . .7226544 .9944162 .7252822 .9984675  .997701 .9813863  .985985 .9991245 .2931133 .2781126  .392314
    "005047" 2001 "3334" .9352504 .9455278 .9814993        . .9835547 .9424446 .9938321 .9804717 .9825272  .997943 .4994849 .4665972 .6783132
    "005047" 2001 "3336" .9718416 .9718416 .9967813 .9959768        . .9710371 .9983903 .9814958 .9871273 .9991948 .4987927 .4794847 .6822199
    "005047" 2001 "3344"  .616863 .6223283 .6079585 .6163103 .6150208        . .9990785 .6039669  .608634 .6225125 .3831979 .3574059 .4824979
    "005047" 2001 "3345" .9737095 .9777689 .9884012 .9860815  .990721 .9783488        . .9847283  .987048 .9990331 .6081576 .5917261 .8641017
    "005047" 2002 "3252"        . .9975759  .964081 .9803877 .9806081  .992728 .9929483 .9316878 .9347729 .9969148  .592772  .583076 .7384309
    "005047" 2002 "3260" .7274722        . .7226544 .9944162 .7252822 .9984675  .997701 .9813863  .985985 .9991245 .2931133 .2781126  .392314
    "005047" 2002 "3334" .9352504 .9455278 .9814993        . .9835547 .9424446 .9938321 .9804717 .9825272  .997943 .4994849 .4665972 .6783132
    "005047" 2002 "3336" .9718416 .9718416 .9967813 .9959768        . .9710371 .9983903 .9814958 .9871273 .9991948 .4987927 .4794847 .6822199
    "005047" 2002 "3344"  .616863 .6223283 .6079585 .6163103 .6150208        . .9990785 .6039669  .608634 .6225125 .3831979 .3574059 .4824979
    "005047" 2002 "3345" .9737095 .9777689 .9884012 .9860815  .990721 .9783488        . .9847283  .987048 .9990331 .6081576 .5917261 .8641017
    "005047" 2002 "3351" .9229289 .9421967 .9826592 .9961466 .9788056 .9383431 .9942198        . .9980734 .9980734  .578035 .5452796 .7032757
    end
Working...
X