Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

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

From |
Hewan Belay <hewan_belay@yahoo.com> |

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

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

Date |
Sat, 17 Apr 2010 22:08:01 -0700 (PDT) |

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/

**Follow-Ups**:**st: RE: variable labels and reshape--reinserting en masse***From:*"Martin Weiss" <martin.weiss1@gmx.de>

**st: RE: variable labels and reshape--reinserting en masse***From:*"Martin Weiss" <martin.weiss1@gmx.de>

- Prev by Date:
**st: Mata calls on Stata variables and macros** - Next by Date:
**RE: st: AW: rename files - "! rename" doesn't work** - Previous by thread:
**st: Mata calls on Stata variables and macros** - Next by thread:
**st: RE: variable labels and reshape--reinserting en masse** - Index(es):