Announcement

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

  • #16
    Dear Clyde,

    I am facing two problems while following the above syntax in my actual data. I am not finding where doing mistakes. I have 15 variables for food and 15 variables for quantity in the actual data..
    Below syntax I tried to use:

    local fishlist1‘ “ “Rui”, “Katla”, “Mrigel”, “Kalibaus”, “Surma”, “Chital”, “Boal”, “Pangash”, “Ritha” ” ’
    local fishlist2 ‘ ” ”Hilsa”, “Jatka”, “Grass Carp”, “Mirror Carp”, “Silver Carp”, “Telapia”, “Swarputi”, “Chital”, “Taki” “ ’
    local fishlist3 ‘ “ “Mague”, “Singi”, “Baim”, “Koi”, “Meni”, “Shapla/padda/rupsha fish”, “Bagda Chingree”, “Golda Chingree”, “Tortoise meat” ” ’
    local fishlist4 ‘ “ “Poona fish”, “Dried fish (Big fish)”, “Gura mach”, “Panch mishali”, “Puti”, “Tengra”, “Moa/mola”, “Dhela”, “Batashi” “ ‘
    local fishlist5 ‘ “ “Kachki”, “Chanda”, “Khalisa”, “Chela”, “Chapila”, “Kajari”, “Tatkeni”, “Bata”, “Ghutum” “ ‘
    local fishlist6 ‘ “ “Bele”, “Chewa”, “Poa”, “Foli”, “Bacha”, “Baicha”, “Darkini”, “Palshe”, “Karfu fish” “ ‘
    local fishlist7 ‘ “ “Kakra”, “Small prawn”, “Dried small shrimp/prawn”, “Dried small fish”, “Fermented fish” “ ‘

    rename x1_07_* item*
    rename item(##) item(#)
    rename x1_08_* quantity*
    rename quantity(##) quantity(#)


    gen long obs_no = _n
    reshape long item quantity, i(obs_no) j(_j)
    drop if missing(quantity, item)
    replace item = trim(itrim(lower(item)))
    _type mismatch_
    keep if inlist(item, `fishlist1') | inlist(item, `fishlist2') | inlist(item, `fishlist3') | inlist(item, `fishlist4') | inlist(item, `fishlist5') | inlist(item, `fishlist6') | inlist(item, `fishlist7')
    _“Ritha””’ invalid name_

    two error messages coming (green color above)

    I assume that I am not doing rename item and quantity correctly

    Thank you so much in advance.

    Sincerely,
    Rumana

    Comment


    • #17
      No, you are not doing the rename wrong. The problem causing the first error message is that the variables x1_07_* are not what you represented them as in your -dataex- in post #13. There you showed them as string variables. The fact that you are getting this error message means that they are not string variables: they are integer-valued numeric variables with attached value labels. Consequently string-manipulation functions like trim() and itrim() and lower() are not applicable to them.

      I'm inclined to believe that what you showed in #13 is not actual -dataex- output from your data, but something you wrote by hand to look like -dataex- output because it is inconceivable to me that the -dataex- program would make this mistake. Alternatively, you showed -dataex- output from some data set that is rather different from the one you are trying to use now. Either way, I can't emphasize enough that you are just getting in your own way by doing things like this. Yours is an example where it is quite important to have a faithful replica (in ways that cannot be seen just in a data table) of a representative sample of the actual data you are working with. You just waste your time and mine by sending data that is not similar to what you need to work with.

      In one sense, however, this concern makes life easier. Instead of needing 7 fish lists, you need only one: and it should contain the numerical values associated with these fish foods, separated by commas, by without surrounding quotes. The reason you only need one such list this time is that -inlist()- will allow up to 255 comparison choices when they are numbers instead of strings. So modify the code accordingly. Create and refer to just a single fishlist. Eliminate the -replace item = trim(itrim(lower(item)))- command. Simply the -keep if ...- command to just -keep if inlist(item, `fishlist')-.

      As for the second message, I believe it arises because you have inserted a blank space between the ` and " at the beginning of the list, and between the " and ' at the end. This confuses the Stata parser and it cannot properly construct the list. `" and "' must be written without included spaces; in fact you should think of them as if they were single characters called compound double opening and closing quotes, respectively. In any case, since it turns out your item variable is really numeric, this ceases to be an issue, because your revised -local fishlist...- command should contain no quotes of any kind at all: just numbers separated by commas.

      Comment


      • #18
        Thank you so much for the details explanation! These are very much helpful!

        Regards,
        Rumana

        Comment

        Working...
        X