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: How to save and use the output of stata command -list-
From
Md Alauddin Majumder <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: How to save and use the output of stata command -list-
Date
Thu, 22 Aug 2013 01:23:14 +0000
Hi Roberto,
I appreciate your suggestion. Thank you very much.
Majumder
________________________________________
From: [email protected] [[email protected]] on behalf of Roberto Ferrer [[email protected]]
Sent: Wednesday, August 21, 2013 8:18 PM
To: Stata Help
Subject: Re: st: How to save and use the output of stata command -list-
With my limited knowledge of Stata, I would have done something like:
* ----- create input --------
clear
input IDnumber str20 state gdp
1 "alabama" 232
2 "alaska" 145
3 "texas" 160
4 "washington" 250
5 "wyoming" 210
end
list
* ------- what you want -------
sort gdp // important!
gen diff1 = abs(gdp - gdp[_n-1])
gen diff2 = abs(gdp - gdp[_n+1])
gen IDclosest = IDnumber[_n-1] if diff1 < diff2
replace IDclosest = IDnumber[_n+1] if IDclosest == .
* ------ clean database -------
drop diff*
sort IDnumber
list
You can include some explicit tie-breaking rule if you want.
On Thu, Aug 22, 2013 at 1:21 AM, Md Alauddin Majumder
<[email protected]> wrote:
> Hi Nick,
> Thanks for your instructive comments. Let me modify the description of my problem. My dataset is the following:
>
> IDnumber State gdp
>
> 1 Alabama 232
> 2 Alaska 145
> .. .... ...
> .. .... ...
> .. .... ...
> 52 Wyoming 210
>
> I want to create a variable (IDclosest) whose each cell will contain the IDnumber of a state closest to the state in question in terms of gdp. I have constructed the following loop to create the variable:
>
> g IDclosest=.
> forval i=1/52 {
> g gdp`i'=gdp[`i']
> g gdp_diff`i'=abs(gdp-gdp`i')
> replace gdp_diff`i'[`i']=.
> qui sum gdp_diff`i'
> list IDnumber if gdp_diff`i'==r(min)
> replace IDclosest[`i']=???
> drop gdp`i' gdp_diff`i'
> }
>
> The 7th and the 8th lines of the loop are what I need to address. Thanks.
>
>
> Regards
> Majumder
>
>
> ________________________________________
> From: [email protected] [[email protected]] on behalf of Nick Cox [[email protected]]
> Sent: Wednesday, August 21, 2013 5:05 PM
> To: [email protected]
> Subject: Re: st: How to save and use the output of stata command -list-
>
> You have asked several variants of this question already:
>
> http://www.stata.com/statalist/archive/2013-08/msg00697.html
>
> http://www.stata.com/statalist/archive/2013-08/msg00844.html
>
> http://www.stata.com/statalist/archive/2013-08/msg00847.html
>
> and the replies have clearly not helped you. So, first, it seems that
> people aren't clear on the real problem, you don't understand their
> replies, or quite possibly both.
>
> If you don't understand the replies you should be asking more
> questions, or trying to make the problem clearer, or both.
>
> -list- does not save anything. Its main job is to list data. See the
> documentation http://www.stata.com/manuals13/dlist.pdf to understand
> this.
>
> That said, I don't understand your question. In your example, the
> first observation is for Alabama. It makes no obvious sense why you
> want to put a descriptor for Wyoming there.
>
> Regardless, Eric Booth answered essentially the same question
>
> http://www.stata.com/statalist/archive/2013-08/msg00846.html
>
> http://www.stata.com/statalist/archive/2013-08/msg00848.html
>
> but you didn't explain what was wrong with his answer.
>
> We need much more detail from you.
>
> Nick
> [email protected]
>
> On 21 August 2013 22:46, Md Alauddin Majumder <[email protected]> wrote:
>
>> I want to save and subsequently use the output that I find from the command -list-. Can anyone tell how to do that in stata? Let me give an example to further clarify. I have a data set like the following:
>>
>> IDnumber State NewID
>>
>> 1 Alabama .
>> 2 Alaska .
>> .. .... ...
>> .. .... ...
>> .. .... ...
>> 52 Wyoming .
>>
>> If I input -list IDnumber if State=="Wyoming"-, it returns '52'. Now I want to fill the first cell of the variable NewID by this output. How can I write code for that? Thanks in advance.
> *
> * 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/
*
* 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/