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

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

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

Date |
Fri, 20 May 2011 23:59:40 -0400 |

Disregard, I solved it! I created a variable that counted all the teachers with the same teacher_id, then used that value to run a substring command which picked out the exact location in my string that I needed. No repeats! Thanks for helping me think things though! -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 On Fri, May 20, 2011 at 11:44 PM, Michael Costello <michaelavcostello@gmail.com> wrote: > 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**:**Re: st: Re: expanding obs, then changing values based on that***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**st: expanding obs, then changing values based on that***From:*Michael Costello <michaelavcostello@gmail.com>

- Prev by Date:
**Re: st: RE: using loop to generate distributions with different means and standard deviations** - Next by Date:
**st: converting column date variables into additional observations** - Previous by thread:
**st: expanding obs, then changing values based on that** - Next by thread:
**Re: st: Re: expanding obs, then changing values based on that** - Index(es):