Announcement

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

  • deleting missing value

    Hey,
    I have a panel data which consists of 254 countries for 1976-2014 for 17variables.
    I want to run synthetic control.
    But for some countries one variable is missing for ALL periods so I want to drop this countries.
    What command should I use?

    Thanks in advance!



  • #2
    So if your country variable is named country and if the variable you want to check for missing values on is called my_var:

    Code:
    by country, sort: egen all_missing = min(missing(my_var))
    drop if all_missing

    Comment


    • #3
      That worked!
      Thank you Clyde!

      Comment


      • #4
        Hi Again,
        Further version of my previous question.

        My command:
        synth gdpperpp popgrowth schooling inflation CAB , trunit(244) trperiod(1996) fig

        New error: for at least one unit predictor inflation is missing for ALL periods specified.

        I think this error means for some countries at least one variable is missing for all pre-intervention period.
        How can I drop these countries?

        Thanks STATALIST!




        Comment


        • #5
          -synth- is not part of official Stata, and I'm not familiar with it. So I don't know if your interpretation of the error message is correct. It is easy enough to modify the code in #2 to eliminate all observations that have a missing value of some variable in each observation of the pre-intervention period, but I haven't seen your data and you haven't explained how to identify which observations are for the pre-intervention period. Let's say, for sake of illustration, that there is a variable called year, and that the pre-intervention period is all years before 1996. Then you would do something like this:

          Code:
          by country, sort: gen byte exclude= min(cond(year < 1996, missing(gdpperpp, popgrowth, schooling, inflation, CAB), .))
          drop if exclude == 1

          Comment


          • #6
            These command give following errors:
            invalid syntax

            the second one:
            exclude not found

            That is from my dataset:
            (Panel data includes 254 countries for years 1976-2014)


            id year CountryName popgrowth schooling inflation CAB investment gdpperpp
            2 1976 Albania 2.2082353 .0036335
            2 1977 Albania 2.2132522 .0037078
            2 1978 Albania 2.0757419 .0037936
            2 1979 Albania 1.989457 .0038073
            2 1980 Albania 2.0479639 12.21 34.547561 .0039492
            2 1981 Albania 2.0029743 -2.1773605 35.121012 .0040065
            2 1982 Albania 2.1132718 -.01769429 37.917069 .0039323
            2 1983 Albania 2.1208853 -.0167473 36.073906 .0039901
            2 1984 Albania 2.1039366 -.02835405 -1.4603149 31.780739 .0039638
            2 1985 Albania 2.0559946 19.26 .35119755 -1.8520548 32.752179 .0039161
            2 1986 Albania 1.9332208 -2.3780011 -.14721104 30.908569 .0040244
            2 1987 Albania 1.99704 .00002862 .2411175 28.418248 .0040385
            2 1988 Albania 1.8867105 1.378e-06 -1.2746943 28.904043 .0038816
            2 1989 Albania 2.687862 -1.888e-06 -1.6829934 31.722071 .0040807
            2 1990 Albania 1.7990856 23.79 -.46870736 -5.6289777 29.30533 .0039414
            2 1991 Albania -.60280968 38.568342 -14.747623 7.338759 .0036111
            2 1992 Albania -.60643473 249.68344 -7.146355 5.1999922 .0033039
            2 1993 Albania -.61016579 114.83565 1.2132849 13.2 .0037968
            2 1994 Albania -.61388051 38.416495 -7.9217443 17.9 .0042785
            2 1995 Albania -.61770366 24.6 5.5733075 -.4743248 21 .0046537
            2 1996 Albania -.6215114 41.275595 -3.2369017 21.154334 .0055312
            2 1997 Albania -.6254301 12.088706 -11.535749 20.491 .004511
            2 1998 Albania -.62933439 8.4323678 -2.4036581 21.023556 .0044639
            2 1999 Albania -.63335227 1.5333308 -4.550831 22.986393 .0051462
            2 2000 Albania -.63735683 29.62 3.981288 -4.3033621 31.734253 .0053142
            2 2001 Albania -.93847043 3.3288511 -5.3512166 38.359969 .0055124
            2 2002 Albania -.2998767 2.4105897 -9.1885631 37.902221 .0054916
            2 2003 Albania -.37414917 5.3797244 -7.0787981 40.472862 .005715
            2 2004 Albania -.41793138 2.3570842 -4.8931241 37.199795 .0059527
            2 2005 Albania -.51179012 34.67 2.6210176 -7.0046202 36.985183 .0063458
            2 2006 Albania -.63091124 2.6960493 -7.4605909 38.979666 .0068641
            2 2007 Albania -.75571876 3.5761948 -10.754245 38.655532 .0073695
            2 2008 Albania -.76734296 3.8576618 -15.6694 35.778428 .008377
            2 2009 Albania -.67389405 2.4226342 -15.371001 34.557793 .0090779
            2 2010 Albania -.49646196 42.03 4.4899814 -11.342167 30.30868 .0091608
            2 2011 Albania -.28330311 2.3102011 -12.945923 31.41358 .0094223
            2 2012 Albania -.15617502 1.0399606 -10.210983 28.32855 .0104286
            2 2013 Albania -.12403185 .21887686 -10.9163 28.358619 .010331
            2 2014 Albania -.10355239 1.6683861 -12.823954 24.483328 .0110052
            3 1976 Algeria 2.8388187 10.840593 43.350276 .0088497
            3 1977 Algeria 2.8668361 11.927099 -11.087167 46.914737 .0097034
            3 1978 Algeria 2.9088983 10.085121 -13.425921 52.219353 .0105193
            3 1979 Algeria 2.9668616 13.987838 -4.9088273 42.545926 .0107613
            3 1980 Algeria 3.029024 3.96 25.862039 .58831537 39.076923 .0104642
            3 1981 Algeria 3.0853902 14.353999 .20271644 36.990595 .0111028
            3 1982 Algeria 3.1199167 1.9397942 -.4051067 37.283238 .0112262
            3 1983 Algeria 3.1223815 6.8047959 -.17458279 37.569532 .0114701
            3 1984 Algeria 3.0871463 8.4335056 .13864045 35.164423 .0115913
            3 1985 Algeria 3.0234177 5.87 4.9725264 1.7514589 34.569169 .0116975
            3 1986 Algeria 2.9489564 2.4053433 -3.5009328 33.555924 .0100037
            3 1987 Algeria 2.8696837 8.8420204 .21162696 27.55638 .0090088
            3 1988 Algeria 2.7773897 9.0609635 -3.4518077 27.639483 .0079178
            3 1989 Algeria 2.6729341 16.011374 -1.9431792 30.073234 .0079931
            3 1990 Algeria 2.5590318 8.71 30.259599 2.2890785 28.58942 .0082243
            3 1991 Algeria 2.4470598 53.788604 5.177063 31.841328 .007838
            3 1992 Algeria 2.3324466 21.926115 30.757488 .0075815
            3 1993 Algeria 2.2016176 13.624425 29.090908 .0070863
            3 1994 Algeria 2.0519281 29.077647 30.080143 .0069713
            3 1995 Algeria 1.8939623 11.3 28.577038 30.908556 .0071707
            3 1996 Algeria 1.7406907 24.021904 25.678412 .0074281
            3 1997 Algeria 1.6050313 7.001963 22.446974 .007082
            3 1998 Algeria 1.4916541 -3.1310887 27.148483 .007242
            3 1999 Algeria 1.4063959 10.856408 28.494456 .0073986
            3 2000 Algeria 1.3466082 13.38 22.677512 25.024286 .0081568
            3 2001 Algeria 1.2956569 -.47306059 26.841058 .0080908
            3 2002 Algeria 1.2584707 1.3204322 30.653369 .008243
            3 2003 Algeria 1.2565119 8.3307285 30.340662 .0089053
            3 2004 Algeria 1.2952959 12.247624 33.263542 .0092646
            3 2005 Algeria 1.3639047 12.46 16.125362 20.523608 31.656412 .0104838
            3 2006 Algeria 1.4367929 10.546696 24.714745 30.170461 .011407
            3 2007 Algeria 1.5075516 6.3953443 22.487958 34.469481 .0116684
            3 2008 Algeria 1.5899102 15.310571 19.85624 37.348437 .0123037
            3 2009 Algeria 1.682726 -11.161609 .31459949 46.87646 .0110685
            3 2010 Algeria 1.7760467 14.5 16.119976 7.5804695 41.430293 .0125955
            3 2011 Algeria 1.8720607 18.228012 8.8363576 37.970948 .0132038
            3 2012 Algeria 1.9480889 7.4523735 5.8415586 39.093206 .0134998
            3 2013 Algeria 1.9748145 -.11227792 .49556244 43.38368 .0133524
            3 2014 Algeria 1.9403992 -.41208465 -4.5343011 45.606876 .0130813
            9 1976 Argentina 1.5613023 438.32278 1.2722423 30.72944 .0041129
            9 1977 Argentina 1.5046993 159.42718 1.9830577 30.941689 .0043241
            9 1978 Argentina 1.4741855 161.37217 3.1954344 27.80016 .0041909
            9 1979 Argentina 1.4802715 147.37704 -.74076931 25.856769 .0044049
            9 1980 Argentina 1.5105354 13.78 90.840802 -6.2030674 25.257786 .0043936
            9 1981 Argentina 1.5445417 106.3641 -5.9890558 22.691089 .0043531
            9 1982 Argentina 1.5663988 207.61768 -2.790974 21.754948 .0044722
            9 1983 Argentina 1.5766281 382.34943 -2.3427783 20.887752 .0047741
            9 1984 Argentina 1.5702653 606.73594 -3.1545541 19.964092 .0050108
            9 1985 Argentina 1.5516027 14.87 625.80214 -1.07672 17.589067 .0048113
            9 1986 Argentina 1.5297977 74.461493 -2.5771978 17.461764 .0052872
            9 1987 Argentina 1.5092051 127.08638 -3.8116688 19.554866 .0055509
            9 1988 Argentina 1.4861719 388.49134 -1.2455746 18.640039 .0058148

            My questions is the same: how I can drop countries whose values are missing for all pre-intervantion period?
            Unfortunatly, the command which you offer does not work.

            Best!
            Last edited by Beyza Emek; 08 Sep 2016, 12:26.

            Comment


            • #7
              Oh, sorry. In the first command, it should be -egen-, not -gen-.

              By the way, the form in which you have posted your data makes it very difficult to import to Stata to try out code on. It would take me far longer to wrestle with that than to fix the code, even if the problem were more complicated. The helpful way to post example data is by using the -dataex- command. If you have not already installed it, run -ssc install dataex-. The simple instructions for using it are in -help dataex-. Please use it in the future for all example data.

              Comment


              • #8
                That worked!
                Thanks Clyde.

                Comment

                Working...
                X