Bookmark and Share

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]

RE: st: comparing variables across time


From   Navid Asgari <navid@nus.edu.sg>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: comparing variables across time
Date   Mon, 30 Apr 2012 20:49:00 +0800

Thanks for your helpful tips, Nic!

Regards,
Navid


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: Monday, April 30, 2012 7:18 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: comparing variables across time

I don't think this simplifies your question. What defines an
observation in your data structure? Why is comparing columns (you mean
variables) going to be easier?

I would rather start from your previous structure. With variables
-Year P1     P2-

gen id = _n
reshape long P , i(id)
bysort P (Year id) : gen seq = _n

. l

     +--------------------------+
     | id   _j   Year   P   seq |
     |--------------------------|
  1. |  1    1   1995   A     1 |
  2. |  2    1   1995   A     2 |
  3. |  3    2   1995   A     3 |
  4. |  4    2   1995   A     4 |
  5. |  5    2   1996   A     5 |
     |--------------------------|
  6. |  6    1   1996   A     6 |
  7. |  7    1   1996   A     7 |
  8. |  8    1   1996   A     8 |
  9. |  1    2   1995   B     1 |
 10. |  5    1   1996   B     2 |
     |--------------------------|
 11. |  2    2   1995   C     1 |
 12. |  8    2   1996   C     2 |
 13. |  3    1   1995   D     1 |
 14. |  4    1   1995   E     1 |
 15. |  7    2   1996   H     1 |
     |--------------------------|
 16. |  6    2   1996   M     1 |
     +--------------------------+

Now as before companies new in 1996 have -seq == 1- and -Year == 1996-.

Nick

On Mon, Apr 30, 2012 at 10:58 AM, Navid Asgari <navid@nus.edu.sg> wrote:
> Thanks Nic,
>
> In fact the values under all values of P1 and P2 that belong to 1995 should be compared with all the values of P1 and P2 in year 1996. In other words two variables of P1 and P2 should be merged. To make this simple, let me rephrase the question:
>
> Year-1995     Year-1996
> ----------    ---------
> A                A
> A                A
> B                A
> D                B
> C                H
> A                A
> A                M
> E                C
>
> Now, I want to compare these two columns and to count how many new characters (which are company names in my original dataset) are under Year 1996 that did not exist in Year-1995:
>
> H and M are new characters, so the code should return 2
>
> Note: E is in 1995, but it does not exist in 1996. So it won't be counted

Nick Cox

> I am not sure I follow this as your question stresses joint occurrence
> in one place but focus on individual occurrence in another. But
>
>  bysort P1 P2 (year) : gen seq = _n
>
> tags successive joint occurrences of -P1- and -P2-. Then
>
> . list P1 P2 if seq == 1 & year == 1996
>
> shows joint occurrences that first appeared in 1996 and
>
> . count if seq == 1 & year == 1996
>
> counts them.
>
> On Mon, Apr 30, 2012 at 10:15 AM, Navid Asgari <navid@nus.edu.sg> wrote:
>
>> I want to do a pair wise comparison of several variables across different years. I would like to know how many new characters under P1 and P2 (together)exists in year 1996 that did not exists in year 1995.
>>
>>
>>
>>  The dataset looks like this:
>>
>>  Year      P1     P2
>> --------  ------- ------
>> 1995        A       B
>> 1995        A       C
>> 1995        D       A
>> 1995        E       A
>> 1996        B       A
>> 1996        A       M
>> 1996        A     H
>> 1996          A       C
>>
>>
>> So the code should show "2", since character M and H exist under P1 and P2 in the year 1996, but not in 1995.

*
*   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/

*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index