Announcement

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

  • String variables: Dropping observation from value

    I am currently cleaning up a survey data set. I'm currently trying to group different answers based on words that may pop up. I am looking to drop certain observations that don't fit into the values - even if they contain the word. How might I go about doing this?

    For example, I would like to drop respondents that have put engineering but only did it at high school as I am only interested at degree responses.

    Thank you in advance!

    * Example generated by -dataex-. For more info, type help dataex clear input strL Q10_a "MEng Chemical Engineering, MA Natural Sciences" "MEng Chemical Engineering PhD Chemical Engineering and Analytical Science" "BSc Mathematics" "BSc Maths" "BSc electrical engineering" "BSc Mathematics" "MEng Civil engineering with German" "BA in Mathematics and Philosophy" "BSc Maths, MSc Maths" "BEng Electronic and Electrical Engineering" "BA, MMath, PhD in pure maths" "BEng Mechanical Engineering" "MEng Chemical Engineering" "Chemical engineering" "Mechanical Engineering" "MEng Mechanical Engineering" "BSc Mathematics" "MEng Computer Systems Engineering" "MEng in Medical Engineering, currently undertaking PhD in Engineering" "BSc Mathematics and Computer Science" "BEng Chemical Engineering MSc Biotechnolgy MPhil Chemical Engineering" "BEng Mechanical Engineering" "BEng Mechanical Engineering" "BSc electronics/software engineering" "MEng Civil Engineering" "BSc Electrical and Electronic Engineering" "MEng Civil Engineering" "BEng (hons) Engineering Geology and Geotechnics" "BSc HONS Electrical and Electronic Engineering" "MEng Aerospace Engineering" "MEng Engineering Science" "Aeronautics and astronautics engineering" "BSc Civil Engineering" "BSc Mechanical Engineering PGCE Physics" "BEng Engineering, Currently studying MSC Engineering" "B.A. Engineering MEng Engineering." "BEng Manufacturing Engineering" "NVQ aircraft maintenance BTEC aerospace engineering" "BSc Mechanical Engineering" "MEng civil engineering graduated 2000 and now studying an msc in railway systems engineering and integration hoping to graduate at the end of the year" "BEng The Special Engineering Programme" "Bsc Applied Maths and Computer Studies" "BEng Aerospace Engineering and MSc Engineering and Management" "BEng (Hons) Automotive Engineering" "Beng civil engineering" "BEng Mechanical Engineering" "BSc Motorsport Engineering" "BEng Mechanical engineering" "HND software engineering" "MEng Mechanical Engineering" "Engineering MEng" "Engineering & Materials Sciences B.Sc., Metallurgy & Science of Materials D.Phil" "BSc Engineering" "MMath Mathematics, PhD Mathematics" "BSc Engineering" "MEng Chemical Engineering" "BEng Hons (1st) Mechanical Engineering" "MEng Civil Engineering" "BA engineering" "BSc Maths & Stats MSc Medical Stats PhD Medical Stats" "MEng Chemical Engineering" "MEng Civil Engineering" "BSc Engineering" "Engineering" "Nuclear Engineering" "BEng Chemical Process Engineering with Biotechnology PhD in Physical Chemistry" "MEng Civil Engineering with European Studies" "Currently working towards BEng Electrical & Electronic Engineering" "BSc Mathematics MSc Military Vehicle Technology" "BEng Production Engineering" "BSc in River and Coastal Engineering" "MEng Architectural Engineering" "mechanical engineering MEng" "BEng Automotive Engineering" "Mechanical Engineering (MEng)" "MEng Aviation Engineering" "MEng Civil Engineering" "MEng Civil Engineering" "BSc Engineering" "Mathematics" "BEng Mechanical Engineering" "MEng Master of Engineering with Honors Design Engineering with an Industrial Placement Year" "BSc Maths & Computing" "MMath Mathematics" "MEng Product Design Engineering" "Civil Engineering" "Electronic Engineering" "Manufacturing Engineering Degree" "Chemical Engineering" "MEng Civil Engineering" "BEng Mechanical Engineering" "MEng Chemical Engineering" "MEng Electrical and Electronic Engineering" "MEng Aerospace Engineering" "Degree Apprenticeship which included NVQ level 2 and 4 in Advance engineering and Manufacturing and Beng in Materials Engineering and Mechanical Design in areospace" "MEng Civil Engineering" "MEng Chemical Engineering" "MEng Electronic Engineering" "MEng Mechanical Engineering" "MSc Engineering" end cls replace Q10_a = "math" if Q10_a =="BSc Maths" g studies = 1 if strpos(Q10_a, "Engineering") | strpos(Q10_a, "engineering") replace studies = 2 if strpos(Q10_a, "math") br if studies ==.

  • #2
    Hi Cassie, for whatever reason all of the line breaks have been removed from your data example. This means that the example data is not useful. Please regenerate the data example and either edit your original post or repost your data example further down in the thread if you would like more help.

    There are a lot of ways to work with string variables. I think you probably want to convert your string variables to factor variables with labels using the -encode- command, but it is difficult to tell without example data. Note well that -encode- is not the correct command if you want to convert a string encoded number to a numeric representation of that number.

    Code:
    help encode

    Comment


    • #3
      Hey Cassie, please watch this; it shows how to properly format your example data as well as present. Also, your question should be much more focused, I can't tell what the problem is just by reading it. Cassie Wright

      When I ask stuff, I typically give full worked or minimal worked examples which clearly delineate what my problem is. I give source code so others can follow me, and I try best I can to fully explain what it is I'd like to do. Critical to this is getting the dataset looking right, as well as asking about what my problem is. So far,
      looking to drop certain observations that don't fit into the values - even if they contain the word. How might I go about doing this? For example, I would like to drop respondents that have put engineering but only did it at high school as I am only interested at degree responses.
      is unclear (from a coding standpoint anyways) since I can't clearly follow what happened or why.

      Comment

      Working...
      X