Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: -merge- (?) problem (was: st: MIME-Version: 1.0)


From   "Ashim Kapoor" <[email protected]>
To   [email protected]
Subject   Re: -merge- (?) problem (was: st: MIME-Version: 1.0)
Date   Tue, 30 Sep 2008 15:22:34 +0530

Okie dokie. Thank you for the tips! Many times I have a question and I
don't know "what to search for " as in what keyword to search for and
I end up posting my questions here, thanks for pointing me in the
right direction.

Ashim.

On Tue, Sep 30, 2008 at 2:38 PM, Eva Poen <[email protected]> wrote:
> As Martin said, there are tools out there to do this.
>
> However, if you are generally interested in parallel lists:
> There is an faq on how to process parallel lists:
> http://www.stata.com/support/faqs/lang/parallel.html
>
> Also, Nick Cox wrote a Stata Tip on lists, which is available free of
> charge thanks to the moving wall policy by StataCorp:
> http://www.stata-journal.com/article.html?article=pr0009
>
> Eva
>
>
> 2008/9/30 Ashim Kapoor <[email protected]>:
>> Hello.
>>
>> Thank you for your reply. I wish to ask another ( related ) question.
>>
>> Suppose I have 2 local variables with the SAME no of "words".
>>
>> local name="One Two Three Four"
>> local numname="one two three four"
>>
>> I want to do something like :-
>>
>> rename One one
>> rename Two two
>> rename Three three
>> rename Four four.
>>
>> So I have 2 questions. How do I get the number of words in the local
>> macro. And 2nd How do I access the 1/2/3/4 "word" of the macro. I have
>> seen the word command for STRING variables, but can I do this for a
>> local variable ?
>>
>> Thank you,
>> Ashim.
>>
>>
>> On Mon, Sep 29, 2008 at 9:03 PM, Eva Poen <[email protected]> wrote:
>>> Ashim,
>>>
>>> Please try and use Stata lingo in your postings: observations (not
>>> rows, or items) and variables (not columns).
>>>
>>> You can do it much easier. -help merge- will provide some good information.
>>>
>>> ***
>>> use secondfile
>>> sort symbol year
>>> save, replace
>>>
>>> use firstfile
>>> sort symbol
>>> merge symbol using secondfile, uniqmaster
>>> save mergefile
>>> ***
>>>
>>> Now you will have ticker as a variable in you second file. Inspect the
>>> _merge variable (see -help merge-) to make sure the outcome is what
>>> you expected.
>>>
>>> Next:
>>> ***
>>> qui levelsof symbol, local(loop)
>>> foreach x of local loop {
>>> drop _all
>>> use mergefile
>>> keep if symbol == "`x'"
>>> save `=ticker[1]'
>>> }
>>> ***
>>>
>>> HTH,
>>> Eva
>>>
>>> 2008/9/29 Ashim Kapoor <[email protected]>:
>>>> Hello Eva,
>>>>
>>>> Thank you for your time. Let me be more clear this time.
>>>>
>>>> In the first file I have 2 variables--> symbol and ticker. The tickers
>>>> are file names I want to save various output files as.  There is a one
>>>> one correspondence between symbol and tickers. For example.
>>>>
>>>>     symbol    ticker
>>>> 1.    ABB       abb
>>>> 2.    BHARTI  bti
>>>> 3.    AIRTEL   artl
>>>>
>>>>
>>>> That is what the first file looks like.
>>>>
>>>> the second file has variables year / symbol / production / etc.
>>>>
>>>> It looks like
>>>>
>>>>   symbol              year    production
>>>> 1.   ABB              1998          92
>>>> 2.   ABB              1999          95
>>>> 3.   BHARTI          1998          61
>>>> 4.   BHARTI           1999         70
>>>> 5.   AIRTEL           2000          80
>>>> 6.  AIRTEL            2001          81
>>>>
>>>> Now I want to save items 1 and 2. ie. items with symbol = ABB in a
>>>> file named "abb.dta"
>>>> I want to saves items 3 & 4 ie. items with symbol= BHARTI in a file
>>>> named "bti.dta"
>>>> and items with symbol = "AIRTEL" in a file named "artl.dta".
>>>>
>>>> So I guess this would be a 2 step procedure.
>>>>
>>>> Step 1 : store all symbols in ONE local macro and store all tickers in
>>>> the 2nd local macro.
>>>>
>>>> Step 2 : Loop through the 2 equal sized loops, do a keep if symbol ==
>>>> ...... and save as the corresponding ticker .
>>>>
>>>> Can u tell me how to do this in stata ?
>>>>
>>>> Thank you,
>>>> Ashim.
>>>>
>>>> On Mon, Sep 29, 2008 at 4:38 PM, Eva Poen <[email protected]> wrote:
>>>>> Ashim,
>>>>>
>>>>> I'm sorry but I don't get it. You have two variables in your first
>>>>> file, called symbol and ticker. What are they? Numeric, string? In
>>>>> your second file you have symbol again (what about ticker?), and many
>>>>> more variables, and you also have more observations (symbol does no
>>>>> longer uniquely identify observations).
>>>>>
>>>>> Now you want to do some operation that looks suspciously like a
>>>>> -merge-, but it's unclear to me. For each symbol from file 1, you want
>>>>> to -use- file 2 and -keep- all observations with this symbol.
>>>>> Following what you said earlier, you will now be left with approx. 100
>>>>> observations and many variables. Now you say you want to save this "as
>>>>> ticker in the 1st file". What do you mean by that? You want to save
>>>>> all 100 observations and many variables, in the first file? And what's
>>>>> that to do with ticker? Ticker already exists in the first file. Do
>>>>> you want to replace it, and with what information? Or do you want to
>>>>> add ticker to the second file?
>>>>>
>>>>> You'll have to be more precise for someone to be able to help.
>>>>>
>>>>> Eva
>>>>>
>>>>> 2008/9/29 Ashim Kapoor <[email protected]>:
>>>>>> Hello everyone,
>>>>>>
>>>>>> I have 2 files.
>>>>>>
>>>>>> The 1st file has 2 columns --> symbol and ticker. [ each symbol is
>>>>>> only in one observation ]
>>>>>>
>>>>>> The 2nd file has many more columns --> symbol and many other vars. [
>>>>>> each symbol is in around 100 observations here ]
>>>>>>
>>>>>> I want to say foreach symbol in 1st file  {
>>>>>>
>>>>>> use 2nd file
>>>>>>
>>>>>> keep if symbol ==above symbol
>>>>>>
>>>>>> save as ticker in the 1st file
>>>>>>
>>>>>> }
>>>>>>
>>>>>>
>>>>>> Can someone tell me how to do this ?
>>>>>>
>>>>>> I guess to start with I would have to save the entire observations in
>>>>>> symbol var in 1st file in ONE local macro and similarly for the
>>>>>> ticker. Can someone tell me how to do this ?
>>>>>>
>>>>>> Thank you,
>>>>>>
>>>>>> Ashim.
>>>>> *
>>>>> *   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/
>>>>
>>> *
>>> *   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/
>>
> *
> *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index