Bookmark and Share

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]

Re: st: Count the number of changing string values


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Count the number of changing string values
Date   Fri, 14 Jun 2013 11:54:37 +0100

I can't see your value labels from here. But suppose that "No" is a
label for value 1.

replace year = `j' if  Drug`j' == 1 & missing(year)

I trust that you will be able to modify that to your situation.


Nick
[email protected]


On 14 June 2013 11:45, Ching Wong <[email protected]> wrote:
> Hi Nick,
>
> So what if -drug*- are numeric variables with value labels, how should
> I change my Command?
>
>
> Thanks!
>
>
> Ching
>
> On 14 June 2013 19:19, Nick Cox <[email protected]> wrote:
>> Code that "doesn't work" but is not shown can not be commented on.
>> Long structure (I prefer to avoid the word "format" here) is not
>> essential for the problem as I understand it, but it is likely to be
>> better for you for most analyses.
>>
>> The year in which people first said "No" is
>>
>> gen year = .
>>
>> qui forval j = 1999/2012 {
>>         replace year = `j' if  Drug`j' == "No" & missing(year)
>> }
>>
>> tab year
>>
>> So,
>>
>> 1. Everybody starts out with missing.
>>
>> 2. If they said "No" in 1999, -year- is changed to 1999
>>
>> 3. If they said "No" in 2000, -year- is changed to 2000, but only if
>> -year- is missing (so values of 1999 are protected)
>>
>> and so on.
>>
>> You didn't explain your datatypes. If -drug*- are numeric variables
>> with value labels, the syntax will differ accordingly.
>>
>> Nick
>> [email protected]
>>
>>
>> On 14 June 2013 10:20, Ching Wong <[email protected]> wrote:
>>
>>> I have the following data set:
>>>
>>> Id     sex   drug1999   drug2000    drug2001      drug 2001
>>>
>>> 1       F       Yes            No          Yes            Unknown
>>>
>>> 3       M       No           Yes          Yes             No
>>>
>>> 5      F         Yes          Yes          Yes            Yes
>>>
>>> 9      M       Unknown    Yes          No             Yes
>>>
>>> 10     F        Yes           No           Yes             No
>>>
>>> I would like to produce a count of to show the number of people who
>>> quit each year, only count the first time they quit and do not care if
>>> they change their status to ‘No’ again.
>>>
>>> What would be the command? I tried to change it to the long formal and
>>> use the lag function, but it doesn’t work.
>>
>> *
>> *   For searches and help try:
>> *   http://www.stata.com/help.cgi?search
>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index