Announcement

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

  • Reshape

    Hey!

    I wonder how could I use reshape, to keep only one observation for every year, without PF and Treatment, and 4 POSTRET and 4 C5 per observation?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(year Treatment PF POSTRET C5)
    1995 0  1   -.06258959   -.05443672
    1995 1  1   -.04878007   -.01230235
    1995 0 10     .0243682 -.0081219645
    1995 1 10    .29053253   -.03238327
    1996 0  1   -.02864548   .015554644
    1996 1  1  -.008444818   .017122192
    1996 0 10   -.00464885   .018017864
    1996 1 10     -.174923    .01251025
    1997 0  1  -.004441842  -.010664557
    1997 1  1     .0945931    .05618503
    1997 0 10    .16133273    .05300198
    1997 1 10     .2606152   -.02023007
    1998 0  1   -.10821836 -.0020010928
    1998 1  1  -.027247274   -.01966048
    1998 0 10    -.1923901  -.008912033
    1998 1 10   -.02608099   -.03519965
    1999 0  1    .12610069  -.064325556
    1999 1  1    .04858679    .04201986
    1999 0 10   -.05919228  -.018305905
    1999 1 10     .4874617    .10914348
    2000 0  1    .05259665   .009659555
    2000 1  1   -.12960732   -.06425608
    2000 0 10   .021079615    .04570518
    2000 1 10  -.023501126   .025826465
    2001 0  1   .062784225  .0022577462
    2001 1  1   -.10950977   -.04774466
    2001 0 10     .1361238    .01361336
    2001 1 10     .3271786    .08065517
    2002 0  1  -.035597265   -.02549423
    2002 1  1   -.10617667   -.03976572
    2002 0 10     .2094567    .05388877
    2002 1 10    .07946272    .06824227
    2003 0  1    .07292191    -.0452106
    2003 1  1    .06298627  -.003759033
    2003 0 10    .17196187    .04035956
    2003 1 10    .18238416   .027393343
    2004 0  1  -.004235355  -.021720765
    2004 1  1   .017285408  -.006449955
    2004 0 10  .0015900885 -.0090287635
    2004 1 10    .03963603  -.007147728
    2005 0  1    -.0215021  -.025990536
    2005 1  1  -.005774237  -.013356016
    2005 0 10    .08841917   .010603352
    2005 1 10   .036350943   .021443876
    2006 0  1   .032947898  -.026843885
    2006 1  1    .08120047  -.015152384
    2006 0 10  -.022264436  -.014675376
    2006 1 10   .024896633    .02478188
    2007 0  1   -.08709063  -.014743632
    2007 1  1   -.02828323   -.04145284
    2007 0 10    .03734744 -.0012899046
    2007 1 10    .05865048  -.008247663
    2008 0  1  -.035577077   -.05458454
    2008 1  1   .014303045   -.06655561
    2008 0 10  .0014968688    .00749701
    2008 1 10  -.036107365   -.02814429
    2009 0  1  -.008806608   -.01453006
    2009 1  1    .07063906   .025290946
    2009 0 10     .0871131   .031613152
    2009 1 10    .04295475   .017743805
    2010 0  1  .0007517777  -.014459757
    2010 1  1   -.04635913   -.03373236
    2010 0 10   .002602269    .01409031
    2010 1 10   .007720996   .006256082
    2011 0  1   -.09272193   -.02076576
    2011 1  1   -.10027213  -.016807783
    2011 0 10  -.007950167    .01116798
    2011 1 10  -.010576516    .01448022
    2012 0  1   -.06731945   -.02497123
    2012 1  1    .04615171   -.02767306
    2012 0 10 -.0082327025    .01082672
    2012 1 10  -.063822806  -.006309513
    2013 0  1    -.0479576  -.019090874
    2013 1  1   -.02562972   .036441606
    2013 0 10   .024701813   .028115595
    2013 1 10   .018392062    .01514944
    2014 0  1   -.05042549  -.019402636
    2014 1  1   -.04476171   -.02302974
    2014 0 10  -.023999644   .016111447
    2014 1 10   -.05622108  -.008709985
    2015 0  1   -.11762933  -.008463339
    2015 1  1   -.10403471  -.014664032
    2015 0 10   -.07629266    .01947039
    2015 1 10   .037056226   .011590023
    end

    Thanks for your time!!

  • #2
    I don't understand what you want. Any application of -reshape wide- to this data will necessarily give you four variables for each existing variable so that you retain the information in the four observations currently associated with each year. Perhaps you don't really want to -reshape- the data, but somehow combine the values in the four observations in some way? I think it would be best if you hand-worked what the results you want would look like for, say, two of the years you show in your example, and show that along with an explanation of how you arrived at it.

    Comment


    • #3
      Here are the variables I want:

      year POSTRET11(Treatment=1 PF=1) POSTRET110(Treatment=1 PF=10) POSTRET01(Treatment=0 PF=1) POSTRET010(Treatment=0 PF=10) C11(Treatment=1 PF=1) C110(Treatment=1 PF=10) C01(Treatment=0 PF=1) C010(Treatment=0 PF=10)

      Thanks a lot!

      Comment


      • #4
        This should do it:
        Code:
        gen suffix = string(Treatment)+string(PF)
        drop Treatment PF
        rename C5 C
        reshape wide POSTRET C, i(year) j(suffix) string

        Comment


        • #5
          Excellent!!! Have a good one~~~

          Comment

          Working...
          X