Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: variable labels and reshape--reinserting en masse |

Date |
Sun, 18 Apr 2010 11:03:42 +0200 |

<> Have you looked at http://www.stata.com/support/faqs/data/labels_reshape.html? Where does the " for any 5 6a 6b 8_2:" syntax come from? HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Hewan Belay Sent: Sonntag, 18. April 2010 07:08 To: Stata List Subject: st: variable labels and reshape--reinserting en masse Dear Statalist, I have been puzzling over this now for a good amount of time, and unsuccessfully scouring the archives for an example like this. I am trying to reintroduce variable labels to variables after the dataset has been reshaped from long to wide. The reason I wasn't able to find the solution in the archives is: Unlike the cases on the web, I have lots of variables with the same stub, and want to write a command that can apply for all of them. To see what I mean, consider the below dataset as a toy example of my case: clear set obs 20 g hh_id= 1 in 1/5 replace hh_id= 2 in 6/10 replace hh_id= 3 in 11/15 replace hh_id= 4 in 16/20 by hh_id, s: g serial_no=_n g biq5 = round(35*uniform()) g biq6a = round(82*uniform()) g biq6b = round(4 *uniform()) g biq8_2= round(16*uniform()) label var biq5 "this is one label" label var biq6a "this is another label" label var biq6b "yet another one" label var biq8_2 "My last and final label" Now, I want to then reshape this so that each household (hh_id) is one row, with the variable "serial_no" used to reshape. In other words, after the reshape, each variable will become 5 variables. In this example I only have 4 "biq" variables, but in my actual dataset I have many, many more, approximately 45, in other cases more. What I would like to do, is for example after the reshape, the variables biq51, biq52, ..., biq55 to all have the same variable label which reads "this is one label". I don't want to need to use 45 lines to do this. Is there some way I can do something akin to: for any 5 6a 6b 8_2: local myvarlab_X : variable label biqX (in order to save the variable labels. And then next, reshape and retrieve labels) reshape wide biq* , i(hh_id) j(serial_no) foreach y in 5 6a 6b 8_2 { foreach v of varlist biq`y' { label variable `v' "`myvarlab_'`y'" } } Unfortunately, the above commands did not work, nor did some variations of the above that I tried. Thanks so much for any insights someone may have! Hewan * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**st: RE: RE: variable labels and reshape--reinserting en masse***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**References**:**st: variable labels and reshape--reinserting en masse***From:*Hewan Belay <hewan_belay@yahoo.com>

- Prev by Date:
**st: RE: variable labels and reshape--reinserting en masse** - Next by Date:
**st: Interacting the treatment variable in treatreg** - Previous by thread:
**st: RE: variable labels and reshape--reinserting en masse** - Next by thread:
**st: RE: RE: variable labels and reshape--reinserting en masse** - Index(es):