Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Combining and repeating value from another dataset


From   Christopher Zbrozek <zbrozek@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Combining and repeating value from another dataset
Date   Sun, 14 Apr 2013 13:36:39 -0400

You can set a local macro to store the value from Y.dta, then reload
X.dta and then create the variable you need, e.g.,

use Y, clear
local myvalue = e[1]
use X, clear
gen e = `myvalue'

There may be better ways, but this will work.

Best,
Christopher Zbrozek


On Sun, Apr 14, 2013 at 1:26 PM, Rahber Thariani <thariani@gmail.com> wrote:
> Thanks Nick.
>
> How do I do this using without actually hard coding the value in? That is I
> want something like
> gen e = {get variable from Y.dta}, because I will be repeating the process
> many times.
>
> The situation arises because I am generating, saving and analyzing
> bootstraps and now want to join the bootstrapped estimates back to the
> source data. So essentially, take a variable, create 50 bootstrapped
> estimates, manipulate the estimates, and then stitch together the original
> variable to the 50 bootstraps. So I have 1 obs in Y.dta and 50 obs in X.dta
> (where X.dta contains the manipulated bootstrapped values).
>
> Any suggestions? Thanks,
>
> R
>
>
> On 4/14/2013 3:38 AM, Nick Cox wrote:
>>
>> You don't need anything fancy.
>>
>> Suppose the one value in Y.dta is 42.
>>
>> In X data, you just go
>>
>> gen e = 42
>>
>> That's it. (If the value is a string value, say "Stata is easy", it's
>> the same story.)
>>
>> That said, why do this? What analyses need it?
>>
>> Nick
>> njcoxstata@gmail.com
>>
>> On 14 April 2013 06:19, Rahber Thariani <thariani@gmail.com> wrote:
>>
>>> A question to which I am sure there is a simple answer, but as a novice
>>> in
>>> Stata, one I am having a hard time finding.
>>>
>>> I have a dataset with variables a, b, c and d (stored in X.dta). There
>>> are
>>> about 5000 observations.
>>>
>>> In another dataset I have only variable e(stored in Y.dta). There is only
>>> one observation.
>>>
>>> I want to create a composite dataset with variables a, b, c, d  and e. I
>>> wish to repeat the same value of e 5,000 times in my new dataset for each
>>> of
>>> the existing 5,000 observations of a, b, c, and d.
>>>
>>> What do you suggest to create this structure?
>>
>> *
>> *   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/
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index