Announcement

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

  • Reshape issue

    I have a data set (from Frederick Solt's inequality data updated). The issue is that there are multiple years for each country, but the years are not consistent over countries. I want to reshape the data into a wide format by year, so I typed:

    reshape wide soltgininet2014-soltabsred2014,i(country) j(year)

    But Stata responded:

    no; data are mi set
    Use mi reshape to perform reshape on these data. mi reshape has the same syntax as reshape.

    Perhaps you did not type reshape. In that case, the command you typed calls reshape and it is not appropriate for use with mi data. Use mi extract or mi xeq to select
    the data on which you want to run the command, which is probably m=0.
    r(119);

    I did not set the data for multiple imputation, which I don't want. I looked up help mi set and tried: mi unregister, but that didn't help either:

    . mi unregister solt*
    (passive variables rel_red abs_red unregistered because not in m=0)
    (imputed variables gini_net gini_market unregistered because not in m=0)
    (variables soltgininet2014 soltginmarket2014 soltrelred2014 soltabsred2014 already unregistered)

    And I could not reshape once I tried this.

    I just tried to upload the data set, but got the error message that a .dta file is not a valid image file (???). So here is what some of the data look like (poorly formatted and without the .'s for missing data for soltrelred2014 and soltabsred2014 that somehow didn't copy well). So any help would be appreciated.


    country year soltgininet2014 soltginmarket2014 soltrelred2014 soltabsred2014
    Afghanistan 2008 29.86312 31.64331
    Afghanistan 2009 30.32648 32.11731
    Afghanistan 2010 30.78983 32.59131
    Afghanistan 2011 31.25318 33.06531
    Afghanistan 2012 31.71653 33.53931
    Albania 1996 29.96074 31.62561
    Albania 1997 29.94694 31.74344
    Albania 1998 30.19448 32.01027
    Albania 1999 30.44203 32.27711
    Albania 2000 30.68957 32.54395
    Albania 2001 30.93711 32.81078
    Albania 2002 31.18466 33.07762
    Albania 2003 31.68344 33.38321
    Albania 2004 32.18222 33.6888
    Albania 2005 33.0187 34.87749
    Albania 2006 33.98886 35.83892
    Albania 2007 34.95903 36.80036
    Albania 2008 35.9292 37.7618
    Algeria 1988 35.51163 38.04881
    Algeria 1989 34.9534 37.48288
    Algeria 1990 34.39516 36.91695
    Algeria 1991 33.83693 36.35103
    Algeria 1992 33.2787 35.78511
    Algeria 1993 32.72047 35.21918
    Algeria 1994 32.16224 34.65326
    Algeria 1995 31.604 34.08733
    Algeria 1996 32.57761 35.157
    Algeria 1997 33.55122 36.22666
    Algeria 1998 34.52482 37.29633
    Algeria 1999 35.49843 38.36599
    Algeria 2000 36.47203 39.43566
    Algeria 2001 36.3372 39.068
    Algeria 2002 36.20238 38.70034
    Algeria 2003 36.06755 38.33268
    Algeria 2004 35.93272 37.96503
    Algeria 2005 35.79789 37.59737
    Andorra 2001 28.2758 45.50099
    Andorra 2002 28.2566 45.98649
    Andorra 2003 28.03536 45.08802
    Angola 1995 40.57835 42.18191
    Angola 1996 44.3719 46.1091
    Angola 1997 48.16545 50.0363
    Angola 1998 51.95901 53.9635
    Angola 1999 55.75256 57.89069
    Angola 2000 59.54611 61.81789
    Angola 2001 59.30595 61.70687
    Angola 2002 59.06578 61.59586
    Angola 2003 58.82562 61.48484
    Angola 2004 58.58546 61.37383
    Angola 2005 58.34529 61.26281


    Ric Uslaner

  • #2
    It's a little unsettling that the data set appears to Stata to have been -mi set- when you did not do that and have no expectation that the originator of the data did either. So I'm a little worried about this. But putting that aside, -mi unregister- will not undo -mi set-, it just unregisters those particular variables. What will undo -mi set- is -mi extract 0-: that removes all the imputed versions of the data set and undoes the -mi- settings. I would suggest doing that and then saving the resulting data set under a new file name.

    Comment


    • #3
      I can't test anything to do with mi right now. If you can't get advice on that or otherwise fix it, a good method is to write out the data to a text file and then import them somehow, and your mi settings, or what Stata is thinking are such, should disappear.

      Your sample data segment has four variables, not six as the header implies.

      Given your extract I could read them in as

      Code:
      input str11 country year gininet ginimarket
      where I am assuming that "gin market" [so to speak] is an unintentional variant on ginimarket. I would certainly drop the 2014 suffixes from those names using any favourite command or device for renaming.

      With that I could reshape in the way you want with

      Code:
      reshape wide gininet ginimarket , i(country) j(year)
      although I can't see that such a structure is better for many purposes.

      Your commands will have more variables named, I imagine.

      Comment


      • #4
        Thanks, there was a variable _mi_miss in the original data set. Dropped it and typed mi extract 0 and then all the data turned into 0's. Went back to the original data set before effectively collapsing it and typed:

        mi extract 0. and Stata told me:

        no; data in memory would be lost

        Comment


        • #5
          Yes, sorry: you have to specify the -clear- option with -mi extract 0- so that Stata knows it's OK to clobber the existing data set. Try -mi extract 0, clear-, and it should work.

          Comment

          Working...
          X