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

  • Drop a variable (the whole column) based on an observation value

    I'm currently working with an input matrix product.
    As the data is like this:

    v1 v2 v3 v4 v5 v6 v7 v8
    country1 country1 country1 country2 country2 country2
    industry1 industry2 industry3 industry1 industry2 industry3
    country1 industry1
    country1 industry2
    country1 industry3
    country2 industry1
    country2 industry2
    country2 industry3
    I need to perform a reshape long in order to be able to work. The problem is that the database is too big and that takes too much time.

    As there are some industries i wont use in my analysis i was thinking on dropping them so it will simplify my dataset before reshaping, which will be faster.

    Is there any way of dropping, say, all variables with industry3?

    something like:

    foreach var in v*{
    drop `var' if `var'[2] == "industry3"
    but this syntax is wrong because drop if only works with observations.

    thanks in advance

  • #2
    if `var'[2] == "industry3"  drop `var'


    • #3
      It works perfectly.

      As usual, thanks for the help Nick!