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
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: foreach or forvalues to re-structure data
Date
Wed, 13 Nov 2013 09:46:21 +0100
This is one of the reasons why the Statalist FAQ tells you say at the
very begining which version of Stata you use if it is not the latest
one. It costs you virtually no time at all, but it can safe us a lot
of time by avoiding that we write an answer that is irrelevant for
your case.
Anyhow, I don't think that that is the problem here: I suspect that
that is just a formating error introduced by the email software. It
should just be the -min()- and -max()- functions (not commands), see
-help min- and -help max-.
-- Maarten
On Wed, Nov 13, 2013 at 9:22 AM, 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/
--
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* 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/