Announcement

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

  • Multiplication scalar with a vector

    Hi!!

    I am trying to run this code:

    gen v_eth= `ethnici1'*b[1,1] + edumo2*b[2,1] + edumo3*b[3,1] + edufa2*b[4,1] + edufa*b[5,1] + female*b[6,1] + b[7,1],

    where `ethnici1' is a local containing the mean of a variable ethnici1 from an OLS regression ==> regress ln_PERCAPITA ethnici1 edumo2 edumo3 edufa2 edufa3 female [iw=FEX_C] if FG==1)

    b is a column vector with 7 rows

    I want to multiply the original values of the variables edumo2, edumo3, edufa2, edufa3 and female with their corresponding estimated cefficients of the regression containes in b

    I get this error,

    gen v_eth= `ethnici1'*b[1,1] + edumo2*b[2,1] + edumo3*b[3,1] + edufa2*b[4,1] + edufa3*b[5,1] + female*b[6,1] + b[7,1]
    *b invalid name


    Thanks for your help!

  • #2
    You say what you think it contains, but Stata appears to think it doesn't exist. Perhaps you are running a do-file line-by-line or chunk-by-chunk, and the creation of local macro ethnici1 is in a different line/chunk from your -gen v_eth = `ethnici1'*b[1,1]...- command. If that's the case you have been tripped up by the fact that when you run a line or group of lines in Stata, any local macros defined therein cease to exist once the running is done and are not available to reference in subsequent lines/chunks. When local macros are used, you must generally run the entire do-file from beginning to end. Similar considerations apply if the local macro is created in a main program and you try to refer to it in a sub-program, or vice versa: the term local refers to the fact that that local macros only exist locally, where they were created.

    If that doesn't resolve your problem, please post back showing all of the code that you ran from the creation of local macro ethnic1 down to the -gen v_eth = ...- command that is throwing the error message.

    Comment


    • #3
      Dear Clyde,
      Thanks a lot for taking your time
      As suggested by you, I had to run all the code! It worked

      Comment

      Working...
      X