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: Combining two datafiles- Union(AND), not Intersection (merge) or Stack (append)


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Combining two datafiles- Union(AND), not Intersection (merge) or Stack (append)
Date   Thu, 21 Mar 2013 19:35:43 +0000

Sounds like a -merge- to me. (We can't comment on what you tried, as
you show no code.)

clear
input str1 Trader      period1   period2 period30
A              23           2            17
B              23           2            17
F             23           2            17
H             23           2            17
end
save file1, replace
clear
set obs 26
gen Trader = word("`c(ALPHA)'", _n)
merge 1:1 Trader using file1

Nick

On Thu, Mar 21, 2013 at 2:46 PM, Mani Subramani <[email protected]> wrote:

> I have a large datafile with activities of traders in different
> periods (transaction file) and a master list of the total set of
> traders.
> I want to create a file that combines observations in the two files (Union).
> What I am looking for is not a merge or append but a Union where
> unique rows in my
> Masterfile that are not present in my transaction file are added..and
> the total number of rows in the final file is the same as the number
> in my Master file.
>
> Below is an explanation with made-up numbers for simplicity.
> I have spent a lot of time trying to work this out..and I have the
> feeling there is a simple way to do this that I missing.
> Thanks in advance
> -----------------------------------------------
>
> Transaction file ( 4 rows - 1 per trader where I have data - 4 columns
> in table) eg
>
> Trader      period1   period2...period30
> A              23           2            17
> B              23           2            17
> F             23           2            17
> H             23           2            17
>
> I have a master list of traders with just names e.g 26 rows , 1 column
> A
> B
> .
> .
> Y
> Z
>
> I need to create a file that will have the union of data in the two
> files (ie it will have 26 rows, with names of traders A-Z when
> combined) and will contain
> 26 rows and 4 columns presenting trading activity data in rows where I
> have them
> eg. combining the two files above, I want a file with
>
> Trader      period1   period2...period30
> A              23           2            17
> B              23           2            17
> C             .              .             .
> C             .              .             .
> E             .              .             .
> F             23           2            17
> G             .              .             .
> H              23           2            17
>              .              .             .
> Y             .              .             .
> Z             .              .             .
*
*   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