Announcement

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

  • Grouping variables under a new variable

    Hello Everyone,

    I am dealing with a data set in which I am given the CountryArea of the certain manufacturing plants. However, I want to group these countries into regions. For example I want Europe-West to include countries--> inlist(CountryArea,"AT","AW","BE","CH","DK","ES"," FI","GE","GR","MC","MT","NL","NO","PT","SE") and Americas to include (CountryArea, "CA", "MX","AR") etc. And I want Americas and Europe-west listed under a new variable called District.

    At this point, I am having both creating the groups I mentioned and compiling them under a new variable.

    I will be happy if you can guide me since I am quite new to these

    Thanks

  • #2
    The following code may point you in a useful direction. One key trick is that inlist cannot use more that values for string variables, so I had to break up the list for Europe-West into two pieces.
    Code:
    generate str20 District = ""
    replace District = "Europe-West"  if  inlist(CountryArea,"AT","AW","BE","CH","DK","ES"," FI","GE","GR","MC")
    replace District = "Europe-West"  if  inlist(CountryArea,"MT","NL","NO","PT","SE")
    replace District = "Americas" if inlist(CountryArea, "CA", "MX","AR")

    Comment


    • #3
      Thank you so much

      Comment

      Working...
      X