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 |
Michael Costello <michaelavcostello@gmail.com> |

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

Subject |
st: expanding obs, then changing values based on that |

Date |
Fri, 20 May 2011 23:44:00 -0400 |

Statlisters, I have a dataset with a variable that asks teachers which section they teach. The options are sections a though e, and more than one answer is allowed. Thus: teacher_id var_a var_b var_c var_d var_e 1 1 0 0 0 0 2 1 1 1 0 0 3 1 0 0 1 1 4 1 0 0 1 0 I need to duplicate any observation that has a 1 for more than one of var_a-var_e. So I did: egen var_total=rowtotal(var_a-var_e) expand var_total sort teacher_id Now, for teacher #2 above for example, I need to assign one (and only one?) of her three observations var_a=1, the second var_b=1 and the third var_c=1. This way I can create a new variable, "section" and have observation for each section. It would look like this in the end: teacher_id section 1 a 2 a 2 b 2 c 3 a 3 d 3 e 4 a 4 d I tried to create a concatenated variable so that I could assign "a" if the first number in the concatenated string (from the first table above) ==1, "b" if the second number were ==1, etc. The problem is that I cannot figure out how to only change the second observation within one teach_id number. Stated differently, it's changing all, not cycling though to the next observation. I'm not sure if this is making sense, but if you have ideas, please let me know. -Michael -- Michael Costello Mathematics & Statistics Teacher, Bethesda-Chevy Chase High School Intern, RTI International 202-246-1627 "To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of." -Sir Ronald Aylmer Fisher, FRS * * 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: expanding obs, then changing values based on that***From:*Michael Costello <michaelavcostello@gmail.com>

- Prev by Date:
**Re: st: Substitute for Notepad++ for editing Stata files in Linux.** - Next by Date:
**Re: st: RE: using loop to generate distributions with different means and standard deviations** - Previous by thread:
**st: Problem with -rcpoisson-** - Next by thread:
**st: Re: expanding obs, then changing values based on that** - Index(es):