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: encode command and then drop


From   Joe Canner <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: RE: encode command and then drop
Date   Sun, 23 Mar 2014 20:37:47 +0000

Julian,

I don't know off-hand how to suppress the value labels in the Data Editor (I don't have access to Stata at the moment), but there are other commands (-tabulate- for example) that have options to do so (e.g, tab Key, nolabel).

There are (at least) two possible ways to do what you are asking with the -drop- command:

1. You can use the value label in the -if- qualifier.  See this post (and it's antecedents) for more information: http://www.stata.com/statalist/archive/2014-03/msg00279.html

2. It's not entirely clear why you would prefer to refer to the firms by an encoded number instead of a string, since that would require you to have a list of all corresponding codes for your entire data set.  However, you are certainly able to do that with -drop if- without any extra coding (e.g., to drop the key that has been encoded as 56: drop if Key2==56).  If all of your keys have a letter followed by a number, and if those numbers are unique, perhaps instead of using -encode- you should strip off the letter and store the numeric part in a numeric variable.  Something like this (depending on the exact format of your keys):

gen n_key=real(substr(Key,2,.))

Regards,
Joe Canner
Johns Hopkins University School of Medicine
________________________________________
From: [email protected] [[email protected]] on behalf of Julian Kochan [[email protected]]
Sent: Sunday, March 23, 2014 4:18 PM
To: [email protected]
Subject: st: encode command and then drop

Hi Statalisters,

i am new to Stata and try to recode strings into numeric Numbers.
I have data of 10.000 firms for the years 2000-2011 such that the first colum displays the firm Key and the second displays the years.
I wanted to drop certain firms. But the command * drop if Key == C0056 led to "type mismatch".
I though it's probably due to Key coded as string and not as a number.
Now, I want to recode the firm names into numbers.

I tried

encode Key, generate (Key2).

I know it is encoded now, but in the data editor it still displays the keys in the variable "Key2" and not the numbers from 1 till 10.000.
I want to encode in such a way, that I can drop in the following step all firms using the drop if Key== (for example) 2 3 10 65 or 98

Thank you guys
*
*   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