{"id":1070,"date":"2018-07-23T10:49:55","date_gmt":"2018-07-23T14:49:55","guid":{"rendered":"http:\/\/www.kaikaichen.com\/?p=1070"},"modified":"2018-07-23T10:51:49","modified_gmt":"2018-07-23T14:51:49","slug":"stata-command-to-convert-string-gvkey-to-numerical-gvkey-or-vice-versa","status":"publish","type":"post","link":"https:\/\/www.kaichen.work\/?p=1070","title":{"rendered":"Stata command to convert string GVKEY to numerical GVKEY or vice versa"},"content":{"rendered":"<p>The default type of GVEKY in Compustat is string. Sometimes, we need it to be a numerical type in Stata (e.g., when we want to use the super handy command <code>tsset<\/code>). The command to convert string GVKEY to numerical GVEKY is very simple:<\/p>\n<p><code>destring gvkey, replace<\/code><\/p>\n<p>The command to revert numerical GVKEY to string GVKEY with leading zeros is as follows:<\/p>\n<p><code>tostring gvkey, replace format(%06.0f)<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The default type of GVEKY in Compustat is string. Sometimes, we need it to be a numerical type in Stata (e.g., when we want to use the super handy command tsset). The command to convert string GVKEY to numerical GVEKY &hellip; <a href=\"https:\/\/www.kaichen.work\/?p=1070\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/1070"}],"collection":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1070"}],"version-history":[{"count":3,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/1070\/revisions"}],"predecessor-version":[{"id":1073,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=\/wp\/v2\/posts\/1070\/revisions\/1073"}],"wp:attachment":[{"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaichen.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}