Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: RE: Problem with "reshape"


From   "Jacki Buros" <jburos@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: RE: Problem with "reshape"
Date   Wed, 4 Oct 2006 13:03:56 -0400

Juanita,

I could be wrong, but I think reshape allows you to specify where the
'j' portion of the data resides within the variable name using the '@'
symbol.

so, with data as you've described :

> date  code1_varx     code1_vary   code2_varx  code2_vary
> 1990        10            20           10          30
> 1991        10            20           10          30
you could type

    . reshape long code@_varx code@_vary, i(id) j(code)

which should give you

> date  code_varx     code_vary   code
> 1990        10            20           1
> 1990        10            30           2
> 1991        10            20           1
> 1991        10            30           2
then you would just have to rename each code_varx to varx to vary, as follows:

unab codevars : code_*
foreach V of local codevars {
       local rename=subinstr("`V'","code_","",.)
       rename `V' `rename'
}

Jacki

On 10/4/06, Riano, Juanita <JRiano@imf.org> wrote:
Philipp,

Thank you! your code is great but I am very sorry because I failed to
mention that my codes are six-digits random numbers,

They look like code741486 code904195


Juanita

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Philipp Rehm
Sent: Wednesday, October 04, 2006 12:08 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: RE: RE: Problem with "reshape"

This may work:

forvalues i = 1(1)300 {
 foreach XY in x y {
  rename code`i'_var`XY' var`XY'_`i'
}
}

reshape long varx_ vary_, i(date) j(code)

rename varx_ varx
rename vary_ vary

You may need to make use of capture, in case your individuals are not
consecutievely numbered.

HTH,
Philipp


Riano, Juanita wrote:
> Thanks Justin, but 'stack' doesn't work because I need to preserve the

> individuals' code.
>
> Juanita
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of White,
> Justin
> Sent: Wednesday, October 04, 2006 11:47 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: RE: Problem with "reshape"
>
> Try the 'stack' command
>
>
>
> Justin White
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Riano,
> Juanita
> Sent: Wednesday, October 04, 2006 11:43 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: Problem with "reshape"
>
> Dear all,
>
> I have a wide dataset organized as follows
>
> date  code1_varx     code1_vary   code2_varx  code2_vary
> 1990        10            20           10          30
> 1991        10            20           10          30
> ...
>
> Where:  code1- code300 identify individuals and varx vary are the
> varnames (I have 9 variables).
>
> What I want is a long dataset that looks like this
>
> date   code   varx   vary
> 1990    1       10      20
> 1991    1       10      20
> ..
> 1990    2       10      30
> 1991    2       10      30
> ..
>
> Using the reshape command hasn't worked for me so far because the stub

> that identifies the name of the variable is at the end of it:
> no xij variables found r(111);
>
> I also tried to transpose the data using the "xpose" command to
> manipulate the names but when you use "xpose" twice the string
> variables are dropped,,,
>
> I would really appreciate any suggestion on how to proceed,,,
>
> Thank you very much,
>
> Juanita Riano
>
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index