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

From |
Andrea Bennett <mac.stata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: once again -reshape- and labels |

Date |
Mon, 16 Jun 2008 19:33:47 +0200 |

Dear Nick, I'm sorry the question was not that clear to you! But the link you provided is exactly what I was looking for... I will check it out asap.

Kind regards,

Andrea

On Jun 16, 2008, at 7:16 PM, Nick Cox wrote:

In addition, the FAQ at

<http://www.stata.com/support/faqs/data/labels_reshape.html>

seems closer to your problem than the one you cite.

-----Original Message-----

From: Nick Cox

Sent: 16 June 2008 18:00

To: 'statalist@hsphsun2.harvard.edu'

Subject: RE: once again -reshape- and labels

You don't say what your problem is beyond "I couldn't get it to work",

so I am not

clear quite what kind of diagnosis or guidance you seek.

Also, the example here is first in terms of Ax1 Ax2 Ax3, then in terms

of Ax1 Bx1 Cx1.

We have to guess what you mean. I'll take the first.

As your variable label is the same, no loop over variables is necessary

to retrieve it.

Suppose we have

. l

+-----------------+

| Ax1 Ax2 Ax3 |

|-----------------|

1. | 1 4 7 |

2. | 2 5 8 |

3. | 3 6 9 |

+-----------------+

. d

Contains data

obs: 3

vars: 3

size: 21 (99.9% of memory free)

------------------------------------------------------------------------

------

storage display value

variable name type format label variable label

------------------------------------------------------------------------

------

Ax1 byte %8.0g Ax

Ax2 byte %8.0g Ax

Ax3 byte %8.0g Ax

------------------------------------------------------------------------

------

Sorted by:

. local varlab : var lab Ax1

. gen i = _n

. reshape long Ax , i(i)

(note: j = 1 2 3)

Data wide -> long

------------------------------------------------------------------------

-----

Number of obs. 3 -> 9

Number of variables 4 -> 3

j variable (3 values) -> _j

xij variables:

Ax1 Ax2 Ax3 -> Ax

------------------------------------------------------------------------

-----

. label var Ax "`varlab'"

. d

Contains data

obs: 9

vars: 3

size: 90 (99.9% of memory free)

------------------------------------------------------------------------

------

storage display value

variable name type format label variable label

------------------------------------------------------------------------

------

i float %9.0g

_j byte %9.0g

Ax byte %8.0g Ax

------------------------------------------------------------------------

------

Sorted by: i _j

Note: dataset has changed since last saved

If you have Bx*, Cx* as well, the code needs extension but I don't think

new principles come into play.

Nick

n.j.cox@durham.ac.uk

Andrea Bennett

I thought I should be able to succeed myself in doing a -reshape long-

and preserve the variable's label, e.g. I have Ax1 Ax2 Ax3 with every

Ax1-Ax3 having the very same label, but even though having a look at

http://www.stata.com/support/faqs/data/variables.html

and trying to borrow from there, I couldn't get it to work. I now

have stored the first variable's label of each variable I need to

reshape (e.g. the label for Ax1 Bx1 Cx1) but cannot get it applied to

the new variables (after reshape) which are called Ax, Bx and Cx.

My code so far:

local lrshp "Ax1 Bx1 Cx1"

foreach v of var `lrshp' {

local l`v' : variable label `v'

if `"`l`v''"' == "" {

local l`v' "`v'"

}

}

Does any of you macro masters have a good line of help?

P.S. If someone got an idea for automatically renaming Ax, Bx and Cx

to A, B, and C, that would be great, too.

*

* 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/

**References**:**st: once again -reshape- and labels***From:*Andrea Bennett <mac.stata@gmail.com>

**st: RE: once again -reshape- and labels***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

- Prev by Date:
**Re: st: 64 bit Stata for the Mac /feature request** - Next by Date:
**RE: st: one-way 95 CI for Ha: diff < 0** - Previous by thread:
**st: RE: once again -reshape- and labels** - Next by thread:
**st: re: local=0802 vs local=802** - Index(es):

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