Announcement

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

  • Variable with missing values for Country of Panel variable

    Dear statalists, I looked for a thread similar but I couldn't find it, I would like to generate a variable which tells me the number of missing values for each Country of my panel Variable, is there a simple way to do it?

    I have a variable called missings, which tells me the number of missing values per observations, maybe it could be helpful.

    This is an example of my dataset

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(LSECI LLF LP LPD LNR1 LRR1 LSFI1 LFDI LPA LHC LGCF LGC LTO) int year long Code float missings
     -.05906565   14.0879 14.930984  4.712685  21.10658  16.79136  2.644121   1.851084  4.465908 1.0399592  .2110638  -2.647118 4.2272005 2002 1 0
     -.24591394   14.0781  14.92724 4.7089434  21.29847 16.932587  2.644121   1.871692  5.303305 1.0449243  .2322228  -1.305063 4.2050004 2003 1 0
     -.14123003  14.06743 14.923062 4.7047644  21.56541 17.168446  2.644121   2.262229  5.966147 1.0498893 .27144402 -1.3467995  4.205396 2004 1 0
       -.306384 14.055966 14.917945 4.6996465 21.670826 17.241358 2.3124382   1.897541  5.978886 1.0548543  .2985963 -1.4614805 4.2608795 2005 1 0
      -.3051425 14.046782 14.911635  4.693337 21.723505 17.269533 2.3124382  2.0074136   4.75359 1.0571066  .3287358  -1.543188  4.307668 2006 1 0
     -.27810135 14.036585 14.904078   4.68578  21.80033 17.303392 2.0947125    2.50954  6.040255 1.0593591  .3236593 -1.5598174 4.4212723 2007 1 0
    -.030295366 14.025968 14.896405 4.6781063 22.039986 17.502705 1.8184465   2.966079  6.293419 1.0616113  .3280275 -1.5985552 4.3496547 2008 1 0
      -.3474659  14.01961 14.889666 4.6713676   21.9574  17.39618 1.8184465   3.108432  5.996452 1.0638638    .32141  -1.571129  4.318752 2009 1 0
     -.46514454  14.01919   14.8847  4.666403  21.87799  17.27282 1.8184465  2.9085834  5.855072  1.066116  .2665441  -1.551308  4.337858 2010 1 0
    -.035892293 14.131644  14.88201  4.663713  21.85601 17.227953 1.8184465    2.79312 3.0445225 1.0683913 .26204434 -1.5845407  4.397144 2011 1 0
      -.3196297 14.088614  14.88036  4.662061  21.76691 17.128485 1.4436355   2.706016         . 1.0706744 .24195415  -1.641688  4.337424 2012 1 1
      -.4346814 14.024563 14.878528  4.660229 21.664717 17.023409 1.8184465   2.979775 2.1972246 1.0729651 .24062423 -1.6026646  4.329071 2013 1 0
      -.4259064  14.03378 14.876457  4.658159  21.76778 17.111092 1.4436355   2.858962  1.609438 1.0752637  .2376825  -1.595205 4.3229113 2014 1 0
     -.53431135 14.080098 14.873545 4.6552467 21.671724 17.009413 1.4436355   2.858676 2.3025851 1.0775702  .2229672  -1.619921  4.273899 2015 1 0
      -.5512535  14.09982 14.871946  4.653648  21.68339 17.027422 1.4436355  2.8716865  1.609438 1.0798844 .22301745 -1.5928887  4.314949 2016 1 0
      -.3419943 14.111864 14.871026  4.652728  21.68783 17.017456  .8813736   2.758384 2.3025851 1.0822065  .2238356  -1.592495 4.3591967 2017 1 0
      -.3953224 14.152034  14.86856  4.650261 21.793623 17.109747  .8813736   2.770412  2.484907 1.0845364 .22192577   -1.59066 4.3419323 2018 1 0
     -.28002593 14.532468  15.06219  3.891472         .         0 2.0947125   .0866728         .  .9733176  .2775328 -1.9887693 4.5333695 2002 2 2
    -.028196264 14.624428 15.127063  3.956346         .         0 1.8184465  1.9442544         .  .9801511 .27030247   -2.64274 4.6279116 2003 2 2
     -.09844093 14.745378 15.218803  4.048087         .         0 1.8184465  2.6106424         .  .9869847 .25458246  -2.712871  4.758943 2004 2 2
      -.0905761 14.895074 15.339004 4.1682863         .         0 1.4436355  2.4974875         .  .9938181  .2639683  -2.870295  4.783759 2005 2 2
     -.11991242 15.066326  15.48325  4.312533         .         0 1.8184465   2.452466         .  .9949921 .25437692 -3.0489945  4.783071 2006 2 2
     -.02269805 15.247632 15.635022 4.4643054         .         0 1.8184465   2.406138         .  .9961659  .3154541  -3.105172  4.918507 2007 2 2
      -.0668502 15.414147 15.774123 4.6034064         .         0 1.8184465   1.251564         .  .9973398 .28887925  -3.057991  5.000676 2008 2 2
       -.332632 15.547885  15.88457 4.7138524         .         0 1.8184465   .4336477         .  .9985136 .35822055  -2.602344  5.033453 2009 2 2
     -.01279965 15.643406 15.961442  4.790725         .         0 1.8184465   1.829643  .6931472  .9996876  .3164409  -2.582916  4.968963 2010 2 1
     -.11703265  15.68317 16.006804  4.836087         .         0 1.8184465   1.461195         0 1.0008683 .26199248   -2.59626   5.02168 2011 2 1
       .2482425  15.69905 16.028345  4.857629         .         0 1.8184465  1.6670634 2.3025851 1.0020515  .2225159 -2.5395694  5.101386 2012 2 1
      -.3284619 15.700108 16.034487   4.86377         .         0 2.0947125  1.6483945  4.770685 1.0032369  .1962979 -2.4077425  5.107616 2013 2 1
     -.12110376  15.69837 16.036255  4.865538         .         0 2.0947125   1.735028  5.627621 1.0044247 .25662667  -2.387197   5.12689 2014 2 1
     -.01549938 15.702588 16.041527  4.870811         .         0 2.0947125  1.6046656  4.543295 1.0056146 .30801505 -2.2762547   5.16605 2015 2 1
    -.018198997 15.704494  16.05206  4.881343         .         0 2.0947125  1.7155985   5.56452 1.0068071  .3263056  -2.266822  5.174723 2016 2 1
      .21953237  15.71407 16.065454  4.894738         .         0 2.3124382   1.713894  5.932245 1.0080018  .3564228 -2.1485274  5.164811 2017 2 1
         -.0003 15.725518 16.080494  4.909777         .         0 2.3124382   1.632165  6.113682 1.0091989    .31334 -2.1936498  5.073477 2018 2 1
      .04458522 16.624577 17.444687 2.6224265  19.83959 15.502812 2.0947125  1.5292293  6.814543  .9966017 .11496622 -2.2200735  3.731765 2002 3 0
      .04538442 16.647512 17.455406 2.6331465 20.119667 15.683085 2.0947125  1.0752832  7.220374 1.0062668 .14262472 -2.0992348 3.7048695 2003 3 0
      -.0663513  16.67055  17.46596 2.6437006 20.250956 15.645785 2.0947125   1.649093  6.733402  1.015932  .1702354   -2.21396  3.706047 2004 3 0
      .15221156 16.678926 17.476322  2.654063  20.57729  15.87393 1.4436355  1.7013153   7.49443 1.0255971  .1749981 -2.2431836  3.702567 2005 3 0
      .07742263 16.696533 17.486477  2.664218 20.801403 15.969286 1.4436355   1.602132  7.980023 1.0285386 .17008574  -2.184042  3.699658 2006 3 0
     -.04208757 16.697803 17.496466 2.6742065  20.91636 15.945004 1.4436355  1.5506835  7.926241 1.0314801 .18240155 -2.0831163  3.712234 2007 3 0
      .09545498 16.699142 17.506392  2.684132  21.06706   15.8873 1.4436355  1.7155385  7.101676 1.0344216 .18192793 -1.9743366  3.698896 2008 3 0
     .014199523 16.718464 17.516388  2.694128  20.95206  15.62926 1.4436355  1.0200889  7.210818 1.0373629 .14603038 -1.7193882  3.528039 2009 3 0
      .04987931 16.718138  17.52391   2.70165 20.976824 15.464103 1.4436355    1.71039  7.219642 1.0403044  .1672581  -1.619244 3.5545194 2010 3 0
     -.00619996 16.736353  17.53544 2.7131805  21.05599  15.33055 1.8184465  1.4634228  7.163172 1.0503118 .17173223 -1.4665565  3.561221 2011 3 0
    -.014099533 16.747871  17.54681 2.7245495 20.867424 14.940557 1.4436355  1.7554705  6.837333 1.0603192  .1546924 -1.4231215 3.4185965 2012 3 0
      .04628348  16.75633    17.558  2.735741 20.790934 14.649368  .8813736  1.3402972  7.167809 1.0703266 .15467353 -1.3561203  3.378745 2013 3 0
     -.04818135 16.760387 17.568995  2.746735   20.7339 14.253847  .8813736   .8545397   7.21524 1.0803338  .1508204 -1.3105452 3.3466284 2014 3 0
     -.13023156 16.778782 17.579775  2.757515  20.71207  13.99631 1.4436355  1.4333627    7.3518 1.0903412 .14691432  -1.240416  3.112903 2015 3 0
      -.3567823 16.795933 17.590347  2.768087 20.478846  13.41865 1.4436355   .5557042  7.538495 1.1003486 .14758006  -1.243151  3.261701 2016 3 0
     -.26527768 16.812971 17.600718  2.778458 20.682314 13.390955 1.8184465   1.345264  7.741534  1.110356  .1319579  -1.501538  3.230393 2017 3 0
     -.23006506 16.838453 17.610876 2.7886164 20.736267  13.10835 1.8184465  1.5677677   7.32975 1.1203634 .12227706  -1.527865 3.4396145 2018 3 0
       .6225917  14.00611 14.925385 4.6687784  20.08419 15.955147  2.644121  2.2433763   5.01728 1.1308392 .14592484  -1.904577 4.3038554 2002 4 0
       .3380259 14.006928 14.920084 4.6634784  20.32535  16.15135  2.644121   2.182216  4.927254 1.1307758 .16328543  -2.287885 4.3826685 2003 4 0
      .04957969 14.008916  14.91436  4.657755 21.177546  16.94265  2.644121   2.631298  5.068904 1.1307124  .1756041 -2.3183925 4.2914267 2004 4 0
    -.003299994 14.012734 14.907857 4.6512513 21.327835 17.061356  2.644121     2.4852  4.836282 1.1306489  .1973548  -2.297399 4.2504897 2005 4 0
     -.04488493 14.014845 14.900126 4.6435194  21.57271 17.261084  2.644121  2.6866724  5.361292 1.1315225  .2183342 -2.1938975 4.1113677 2006 4 0
       .6723793  14.01879 14.891405  4.634799  21.91377 17.560259   2.49178    2.67919  5.099866 1.1323962 .21865687 -2.1521213 4.0426135 2007 4 0
      .03928989 14.017524 14.882844 4.6262374 22.060406  17.64872   2.49178   2.787862  4.844187 1.1332699  .2216643 -2.1220007  3.998977 2008 4 0
      .02409767 14.035967 14.876107  4.619501 21.780924 17.344574  2.644121  2.8698344  5.049856 1.1341436 .15810846 -1.9235648  4.047851 2009 4 0
     -.02459752 14.081112 14.872368 4.6157618  21.92884 17.417671  2.644121   2.443988  4.820282 1.1350174 .13909069 -1.8084183 4.1688795 2010 4 0
       .3150617 14.105152 14.872097 4.6154914 22.003435 17.450344  2.644121   2.561752 4.7184987 1.1358942  .1155908 -1.6793517 4.2403994 2011 4 0
      .44533345 14.112329 14.874772 4.6181655  22.06612 17.460953  2.644121   2.246985  4.762174  1.136772 .10703722 -1.7753198  4.330229 2012 4 0
       -.151915 14.119312  14.87939 4.6227846 22.201315 17.563032  2.644121  1.8532603   4.59512  1.137651 .09951708 -1.8444237  4.350988 2013 4 0
      -.1932941 14.110133  14.88449  4.627883 22.148117 17.487003  2.644121   1.966301 4.6821313 1.1385309 .10693416 -1.4778807 4.3278193 2014 4 0
      -.1685015 14.100274 14.888996   4.63239  21.81618    17.143   2.49178  1.3232837  4.394449 1.1394119 .10323358 -1.6880323 4.2722406 2015 4 0
      -.2499881 14.081555  14.89261 4.6360025 21.740185 17.064323   2.49178  1.8692235 4.5325994  1.140294 .09526194  -1.673722 4.3317585 2016 4 0
      -.4087246  14.07666 14.895548  4.638942  21.84732 17.150183   2.49178  1.5200377  4.304065  1.141177  .0991709 -1.4746176 4.4682317 2017 4 0
     -.04378601 14.035137 14.897905 4.6412997 21.813856 17.089222   2.49178   1.461397 4.6051702 1.1420612 .11985386 -1.5487416  4.526918 2018 4 0
     -.05017894 16.112808  16.79366  .9392296  20.65225 16.521225  .8813736   2.022845  9.518707 1.2574444 .27348495 -1.8927412  3.727073 2002 5 0
    -.017399123 16.130686    16.806  .9515696 20.988047  16.82636  .8813736   1.410111  9.477003  1.254296  .2896952 -1.8852736  3.696256 2003 5 0
     -.19594374 16.142567 16.817593  .9631631 21.223713 17.029453 1.4436355    2.64489  9.452423 1.2511476 .29637644  -1.885259  3.614176 2004 5 0
     -.13271011 16.172384 16.830791   .976361  21.35497 17.123444 1.4436355 -1.9978592   9.30374 1.2479992  .2940322 -1.8992018  3.670491 2005 5 0
      -.1798292  16.19534 16.845543  .9911132 21.431145 17.149948 1.4436355  2.1175053  9.151227 1.2448508 .29244894  -1.899504  3.728202 2006 5 0
     -.09854045 16.211004  16.85179  .9973601  21.71046 17.380365 1.4436355   2.352671  9.326879 1.2417024  .2983859 -1.8973753 3.7388935 2007 5 0
      -.3878061 16.237396  16.87183 1.0174003  21.83908  17.46472 1.4436355   2.161534   9.38118  1.238554 .27483147 -1.9094722   3.75818 2008 5 0
      -.3457689 16.258207  16.89244 1.0380107  21.70508 17.281914 1.4436355  1.8469965  9.426258 1.2354057 .26572773 -1.8861258  3.824238 2009 5 0
       -.461719  16.27528 16.907995 1.0535656  22.03939  17.60462 1.4436355   1.841009  9.585827 1.2322572 .24782175 -1.9125392  3.704991 2010 5 0
      -.4028176 16.289589  16.92189 1.0674609  22.31221 17.816788 1.4436355  2.2505326   9.79127 1.2361013  .2504762   -1.89753 3.7354465 2011 5 0
       -.513706 16.303083 16.939348 1.0849191 22.294094 17.780277 1.4436355  2.0250294  9.782675 1.2399453 .26510152 -1.9236387   3.76608 2012 5 0
      -.5973379 16.317574  16.95656 1.1021307 22.287455  17.77488 1.4436355  1.9451405  9.747536 1.2437893 .28273955  -1.966788  3.718643 2013 5 0
     -.56091994 16.329256 16.971476 1.1170462  22.24588 17.718618 1.4436355  2.1664617  9.868068 1.2476333 .28110796 -1.9249603  3.749657 2014 5 0
      -.4427885 16.348059 16.985868 1.1314384  22.19328 17.671532 1.4436355   1.957221 10.047502 1.2514774 .25897855 -1.8185545  3.725558 2015 5 0
     -.05836686 16.360418 17.001488 1.1457934 22.137587  17.62118 1.4436355  1.9806093 10.075085 1.2553215  .2408086 -1.8226395  3.708134 2016 5 0
     -.56779563 16.379559 17.018333 1.1626387 22.110523 17.557451 1.4436355   1.981318  10.03197 1.2591655  .2335464 -1.8094656  3.733344 2017 5 0
     -.52214813 16.399784 17.033693 1.1779997  22.03775 17.465998 1.4436355  2.1636376  9.744785 1.2630095  .2162369   -1.79849 3.7672896 2018 5 0
      .18573034  15.19508 15.905145  4.583622   22.1022 17.738708         0 .064791046  7.355002 1.1472491  .2441067  -1.849994  4.465312 2002 6 0
       1.411701 15.199821 15.910016 4.5884933  22.33116  17.95468         0  1.5967722   7.21524 1.1524333 .25680533 -1.9122317  4.458842 2003 6 0
      1.4244202 15.174218  15.91622 4.5946975 22.341064 17.947336         0   .9218159  6.867974 1.1576177 .25976226 -1.9266984  4.508575 2004 6 0
        1.38949 15.206183 15.923033   4.60151  22.25518 17.836388         0    3.93867   6.84375  1.162802 .25960365 -1.9424547 4.5436544 2005 6 0
      1.3374983 15.220316  15.92798 4.6064577  22.33955 17.902014         0  1.8572963  7.355002 1.1679863  .2578669  -1.918473 4.5858684 2006 6 0
        1.34533 15.241635 15.931222 4.6097236 22.486496 18.026993         0  3.5684865  7.120444 1.1731707 .26856208 -1.9518405  4.612476 2007 6 0
       1.308955  15.25293 15.934353  4.612854 22.576374 18.097496         0   1.174841  7.170888 1.1783549  .2748632 -1.8598052 4.6256948 2008 6 0
      1.3233646 15.264066 15.936972 4.6154737 22.548357 18.050764         0  1.9857126  7.004882 1.1835393 .26672018 -1.8013655 4.4666233 2009 6 0
      1.3604977 15.268692 15.939376 4.6179624 22.509506  18.00322         0 -2.4265394  7.029973 1.1887236 .26752543 -1.8155086 4.5953197 2010 6 0
      1.3351383 15.275343 15.942747 4.6214542 22.595316 18.070862         0  2.3754082  7.088409  1.191997  .2893963   -1.82757 4.6549387 2011 6 0
       1.303302 15.286207 15.947307  4.626098  22.52438  17.97959         0  1.0628818  7.271704 1.1952707  .2993786  -1.832444 4.6554084 2012 6 0
      1.3745633 15.295732   15.9532  4.632271   22.5986 18.037704         0   .1047006  7.135687  1.198544 .29860285 -1.7656025  4.645029 2013 6 0
      1.3422527 15.300003 15.961016 4.6401834 22.591955 18.009535         0   .3782864  6.869014 1.2018176 .28732166  -1.776457  4.639606 2014 6 0
      1.3703715 15.310846 15.972225 4.6514297 22.468494 17.863325         0 -1.4826987  7.212295  1.205091 .29165694  -1.760522 4.6291533 2015 6 0
       1.322768 15.327868  15.98304 4.6622434  22.47683 17.853346         0 -2.6878335  7.034388 1.2083647  .3003633 -1.7270216  4.614943 2016 6 0
    end
    label values Code Code
    label def Code 1 "ALB", modify
    label def Code 2 "ARE", modify
    label def Code 3 "ARG", modify
    label def Code 4 "ARM", modify
    label def Code 5 "AUS", modify
    label def Code 6 "AUT", modify

  • #2

    "my panel Variable" -- any particular variable or do you mean several?

    If you have one variable in mind then something like


    Code:
    egen nmissing_foo = total(missing(foo)), by(Code)
    counts missings by country. If you have several variables in mind, then you could go

    Code:
    egen rowmiss = rowmiss(foo bar bazz whatever) 
    egen nmissing = total(rowmiss), by(Code)

    Comment


    • #3
      Thank you Nick Cox one variable which is Code. But maybe you were asking which variable of my dataset, related to Code, well in that case many variables
      Last edited by Marco Astori; 11 Jan 2022, 09:44.

      Comment


      • #4
        Code:
        count if missing(Code)
        In your data example Code is the country variable.

        Comment


        • #5
          Thank you Nick Cox I have many variables in my panel data whose some values are missing, I want to count them by Country, represented by variable Code, the advice you gave me in

          Code:
          egen rowmiss = rowmiss(foo bar bazz whatever)
          Code:
          egen nmissing = total(rowmiss), by(Code)
          I think is correct

          Comment

          Working...
          X