Announcement

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

  • Invalid Syntax r(198)

    Hi everyone,

    I was wondering if I could get help to figure out the problem with one of my commands. I have been over it several times, and it would be great to get another opinion!

    I have to calculate bid-ask spread of stocks of 194 companies (company name = ticker), using the first order serial covariance between the returns of the stocks. The returns are calculated using transaction prices, which is the variable close.

    The command I am having problem with is:

    forvalues i = 1/`N'{
    quietly correlate return lreturn if ticker_new==`i', covariance
    replace cov_returns = r(cov_12) if ticker_new==`i'
    }

    You can find the rest of the do-file below


    Thank you for your time and help!
    Sarika
    Click image for larger version

Name:	Screenshot 2018-12-06 at 20.27.48.png
Views:	2
Size:	1.56 MB
ID:	1473775


  • #2
    It is not apparent why you are getting a syntax error here. My best guess is that you are running the code one line at a time, or in groups of lines, and that the line were local macro N is defined is not run at the same time as the -forvalues- command that uses it. When you run code from a do-file by highlighting selected lines any local macro defined goes out of existence after those selected lines finish running. So -forvalues i = 1/`N' {- expands to -forvalues i = 1/ {- which is, indeed, a syntax error.

    Some remarks about posting. Please read the Forum FAQ. There you will learn, among other things, that screenshots are discouraged. If somebody needed to work with your code, it is not possible to transfer it from a picture into Stata without tediously retyping the whole thing (and possibly introducing discrepancies from what you did). Always post code by copy/pasting from your do-file directly into the forum editor between code delimtiers. (FAQ #12).

    You will also learn that marking your request as "Urgent" does nothing to improve your chances of getting a quick response, and, if anything, it is off-putting to some of the more active Forum members.

    You will also learn that the posting of homework assignments is deprecated. I cannot be sure whether what you are asking for help with here is a homework assignment or not. But the do-file name is strongly suggestive, as is your apparent urgency. In the future, please seek homework help only from sources that are consistent with the policies of your school and your instructors. I chose to respond to this only because of a bit of lingering uncertainty about whether this is homework or not, and because the response did not seem to require any modifications of your code.

    Comment

    Working...
    X