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: foreach or forvalues to re-structure data


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: foreach or forvalues to re-structure data
Date   Wed, 13 Nov 2013 08:48:37 +0000

The "3D" you see in "=3D" is just a side-effect of character
conversion. Just ignore all references to "3D".

gen minid = min(country, partner)
gen maxid = max(country, partner)
drop country partner
collapse (sum) trade, by(minid maxid)
Nick
[email protected]


On 13 November 2013 08:22, Saleheen, Jumana
<[email protected]> wrote:
> Hi Jo,
>
> Thanks for this suggestion - it does look more efficient.  Only problem is that I don't seem to have the 3Dmin command on my stata (I have stata12).
>
> Is that a stata13 command?  Or can - download it?
>
> If not, is there another command I can use ?
>
> Thanks
> Jumana
>
>
> ----- Original Message -----
> From: Joe Howard [mailto:[email protected]]
> Sent: Tuesday, November 12, 2013 11:04 PM
> To: statalist <[email protected]>
> Subject: Re: st: foreach or forvalues to re-structure data
>
> *************************
> This email has reached the Bank via the Internet or an external network
> *************************
> Try using collapse instead -- it's more efficient...
>
> gen minid=3Dmin(country, partner)
> gen maxid=3Dmax(country, partner)
> drop country partner
> collapse (sum) trade, by(minid maxid)
>
> On Tue, Nov 12, 2013 at 5:24 PM, Saleheen, Jumana
> <[email protected]> wrote:
>> Hi,
>>
>> I’d like to use the commands foreach or forvalues to re-structure my dataset. Happy to use other commands if they work better.
>>
>> What I have is a dataset that  looks like this:  country 1 trades with country 2 and 3, but not with itself
>>
>> country       partner           trade
>> 1              1              0
>> 1              2              20
>> 1              3              30
>> 2              1              10
>> 2              2              0
>> 2              3              30
>> 3              1              20
>> 3              2              10
>> 3              3              0
>>
>> And I want to transform the data to look like this:
>>
>> Rowcol  sumvar
>> 12,21    30
>> 13,31    50
>> 23,32    40
>>
>> What I want is the pair-wise trading between two countries.
>>
>> So, in the end the number of observations I have should be much smaller, and equal to the pairs of countries in my data set.  In the above example, it would be 3.
>>
>> Thanks
>> Jumana
>>
>> ***********************************************************************************
>> This e-mail is intended for the addressee(s) named above and any other use is prohibited. It may contain confidential information. If you  received this e-mail in error please contact the sender by return e-mail.
>>
>> The Bank of England does not accept legal responsibility for the contents of this message if it has reached you via the Internet, as Internet communications are not secure. Any opinions expressed are those of the author and are not necessarily endorsed by the Bank of England.
>>
>> Recipients are advised to apply their own virus checks to this message .
>> ***********************************************************************************
>>
>> _____________________________________________________________________
>> This e-mail has been scanned for known viruses by the Messagelabs SkyScan Service.
>>
>> *
>> *   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/
>
>
>
> --
> _______________________________________________
> Joe Howard                                                     [in] LinkedIn
> Doctoral Student
> Center for the Study of Higher and Postsecondary Education
> University of Michigan
>
> *
> *   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/
>
> _____________________________________________________________________
> This e-mail originated from the Internet and has been scanned for known viruses by the Messagelabs SkyScan Service.
>
> _____________________________________________________________________
> This e-mail has been scanned for known viruses by the Messagelabs SkyScan Service.
>
> *
> *   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