Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • dealing with string variables

    Currently I'm working with data sets containg information on bilateral trade for more than 20 countires from 1990 till 2018. I'm interested in values only for Germany. I had the variables named reporter and partner. They have been marked: AUS, CHN, DEU and so on. They were red. I used a code encode reporter, gen(reporternr). After doing so I have variables marked blue. I wanted to keep the observations only for Germany. I typed keep if reporternr==DEU. However, I can see DEU not found. Could anybody help me

  • #2
    reporternr is now numeric, so it is now comparable with a numeric variable or a numeric scalar or a numeric value. But manifestly DEU is not a numeric value yet Stata holds out hope that it is a numeric variable or scalar, but neither is in your dataset; hence the "not found" message.

    No, if you want Germany only you can go straight there. say with

    Code:
    keep if reporter == "DEU"  | partner == "DEU"
    or more subtly

    Code:
    keep if inlist("DEU", reporter, partner)
    and there then seems no point to the encode.
    Last edited by Nick Cox; 20 Dec 2021, 10:31.

    Comment

    Working...
    X