Announcement

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

  • Reshape long multiple variables error invalid "var" 198

    Hi all,
    I am having trouble with the reshaping long command. I have read the previous posts, but I was not able to find the solution to my problem. I would appreciate having your advice.
    I want to reshape multiple variables at once.
    These are some of the variables in the dataset. Each variable has 7 repeated measures, for instance, tax_1, tax_2, tax_3, tax_4, tax_5, tax_6, tax_7. Bellow, I only copied 2 of them.

    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str14 idspot long(bevfood_1 tax_1 regul_1 hical_1 hisug_1 hisatfat_1 hisod_1) str9(subcat_1 macrocat_1) long(bevfood_2 tax_2 regul_2 hical_2 hisug_2 hisatfat_2 hisod_2) str4 subcat_2 str7 macrocat_2
    "040216_CHV_018" . . 999999999 999999999 999999999 999999999 999999999 "" "" . . 999999999 999999999 999999999 999999999 999999999 "" ""
    "052816_C13_013" 2 0 1 1 0 0 0 "512" "5" 2 0 1 1 0 0 0 "512" "5"
    "042716_CN_026" 2 0 0 0 0 0 0 "418" "4" 999999999 999999999 0 0 0 0 0 "418" "4"
    "041216_M_051" 1 2 1 0 1 0 0 "201" "20" 1 2 1 0 1 0 0 "201" "20"
    "052816_M_030" 2 0 1 1 0 0 0 "1211" "12.1211" 2 0 1 0 0 0 1 "1211" "12.1211"
    "040216_M_025" 2 0 0 0 0 0 0 "1111" "11" 1 0 0 0 0 0 0 "231" "23"
    "052216_CN_036" 2 0 0 0 0 0 0 "813" "8" 2 0 0 0 0 0 0 "413" "4"
    "051316_CHV_112" 2 0 0 0 0 0 0 "612" "6" 2 0 0 0 0 0 0 "612" "6"
    "053116_CN_024" 2 0 0 0 0 0 0 "113" "1" 2 0 0 0 0 0 0 "111" "1"
    "051316_M_008" . . 999999999 999999999 999999999 999999999 999999999 "" "" . . 999999999 999999999 999999999 999999999 999999999 "" ""
    "051316_CHV_027" 2 0 1 0 0 0 1 "611" "6" 2 0 0 0 0 0 0 "612" "6"
    "040216_C13_041" 2 0 0 0 0 0 0 "1111" "11" 1 0 0 0 0 0 0 "231" "23"
    "040816_C13_049" 2 0 0 0 0 0 0 "813" "8" 2 0 0 0 0 0 0 "813" "8"
    "052216_D_049" 2 0 1 0 1 1 0 "418" "4" . . 999999999 999999999 999999999 999999999 999999999 "" ""
    "041216_F_017" 2 0 0 0 0 0 0 "3811" "38" 2 0 0 0 0 0 0 "3811" "38"
    "042116_M_114" 2 0 1 1 0 0 0 "512" "5" 1 2 1 0 1 0 0 "201" "20"
    "052816_DK_079" 999999999 999999999 999999999 999999999 999999999 999999999 999999999 "N/A" "N/A" . . 999999999 999999999 999999999 999999999 999999999 "" ""


    This is the code I used and the error I got:

    . reshape long regul_@, hical_@, hisug_@, hisatfat_@, hisod_@,subcat_@, macrocat_@, prodsmallestcat_@, i(idspot) j(adprod)
    invalid 'hisug_'
    r(198);
    end of do-file
    r(198);

    Any help will be much appreciated.
    Best
    Fernanda

  • #2
    Well, I can't explain why Stata chose to single out hisug for its error message, but the whole thing is wrong. You have many commas in there that do not belong. In fact the only comma in the entire command should be the one before i(idspot). No other commas should be there. Get rid of the excess ones and it will run just fine.

    Some additional points:

    1. Is there a reason you are not also reshaping the bevfood and tax variables?

    2. Although they do no harm, you do not need the @'s in your command. When no @ is specified, -reshape- defaults to assuming you want the j() variable to come from the end of the variable name. @ is only necessary if you want to pull j() from the beginning or middle of the variable name.

    Comment


    • #3
      Hi Clyde,
      I followed your suggestions and it worked.
      Thank you so much!!!

      Comment

      Working...
      X