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 |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

Date |
Sat, 21 May 2011 08:31:30 +0100 |

Although you solved your problem, other ways of doing it may be of interest. Here's one: reshape long var_ , i(teacher_id) string keep if var_ drop var_ On Sat, May 21, 2011 at 4:59 AM, Michael Costello <michaelavcostello@gmail.com> wrote: > 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! > 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. * * 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/

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

**st: Re: 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:
**Re: st: RE: RE: Creating a group variable based on values in observations** - Previous by thread:
**st: Re: expanding obs, then changing values based on that** - Next by thread:
**st: converting column date variables into additional observations** - Index(es):