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]

st: RE: replace values through observations with criterion


From   Joe Canner <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: replace values through observations with criterion
Date   Tue, 15 Oct 2013 23:53:42 +0000

Fouad,

It sounds like what you want is this (at least for the example you provided):

. bysort Product Partner Year: gen TargetTariff=Tariff if Reporter=="UK"
. bysort Product Partner Year:  replace Tariff=TargetTariff if Reporter=="Germany"

Note, however, that this will replace the Germany tariff with the UK tariff for *every* combination of Product, Partner, and Year, and it is not clear that this is what you are asking for.  Note also that you will have to repeat this process for every pair of Reporters that you want to swap.  As Nick pointed out, if you have a particular criterion in mind for making this replacement, it would be helpful to know that so as to make the code more generalizable.

Regards,
Joe Canner
Johns Hopkins University School of Medicine
________________________________________
From: [email protected] [[email protected]] on behalf of Abssi, Fouad [[email protected]]
Sent: Tuesday, October 15, 2013 7:12 PM
To: [email protected]
Subject: st: replace values through observations with criterion

I would like to copy a value of a variable in an observation and replace it to another observation in the same variable with criterion. I am using Stata 12.1 for Windows. I have 1754298 observations, and five variables: reporter, product, year, exporter, and tariff ON tariff data. My data looks like this.

Reporter        Product         Partner                 Year            Tariff
GERMANY 111             Australia       1992            .
GERMANY 111             Australia       1993            4.36
GERMANY 111             Canada  1995            7.01
GERMANY 123             Canada  1992            0
GERMANY 123             Canada  1995            5
GERMANY 251             Chile   1993            2.81
UK      111             Australia       1992            3.2
UK      111             Australia       1993            3.75
UK      111             Canada  1995            7
UK      123             Canada  1992            5.94
UK      123             Canada  1995            5.48
UK      251             Chile   1993            4.29
USA     111             Australia       1992            0
USA     111             Australia       1993            4
USA     111             Canada  1995            5
USA     123             Canada  1992            2.73
USA     123             Canada  1995            3.62
USA     251             Chile   1993            4.39

I would like to tell Stata to copy tariff value from the observation where UK is Reporter (for example) to the observation where GERMANY is Reporter (for example), and (Product, year, and Partner are the same). Please note that the number of observations is 1754298, and for Reporter and Partner there are 50 countries, for Product there are almost 26 product, for Year there is 18 years.

Many Thanks,
Fouad Abssi

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