Announcement

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

  • Reshaping and keeping labels

    Hello!
    As context, I'm estimating several regressions with around 900 parameters. I need to save around 400 of them (the ones that are an interaction, so I can then merge them back into the data set and do a scatter plot). I'm using statsby to save the parameters to a dataset, however, statsby gives us something like:

    . des _stat_619

    Variable Storage Display Value
    name type format label Variable label
    ----------------------------------------------------------------------------------------------------------------------------
    _stat_619 float %9.0g _b[4672.cae4#c.educ]

    When reshaping, the 619 means nothing to me. I actually only care about the 4672 in the label.

    Practically, my problem can be explaining in the following manner:
    Code:
    clear
    input id x2007 x2008 x2009
    1 12 16 18
    end
    
    foreach v of varlist x* {
    label variable `v' "`=substr("`v'",1,1)' factor(`=substr("`v'",length("`v'")-3,4)')"
    }
    
    desc *
    
    //This is what I'm getting (see list):
    reshape long x, i(id) j(year)
    list
    
    //This is what I want (see list):
    label define yearlbl 2007 "x factor(2007)" 2008 "x factor(2008)" 2009 "x factor(2009)" , replace
    label values year yearlbl
    list
    Thanks for you time!
    Hélder

  • #2
    Code:
    clear
    input id x2007 x2008 x2009
    1 12 16 18
    end
    
    foreach v of varlist x* {
    label variable `v' "`=substr("`v'",1,1)' factor(`=substr("`v'",length("`v'")-3,4)')"
    }
    
    foreach v of varlist x*{
        gen v`v'= "`:var lab `v''"
    }
    
    reshape long x vx, i(id) j(which)
    l
    Res.:

    Code:
    . l
    
         +----------------------------------+
         | id   which    x               vx |
         |----------------------------------|
      1. |  1    2007   12   x factor(2007) |
      2. |  1    2008   16   x factor(2008) |
      3. |  1    2009   18   x factor(2009) |
         +----------------------------------+

    Comment


    • #3
      Thank you very much Andrew Musau, it did exactly what I needed.

      Comment

      Working...
      X