Announcement

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

  • Invalid syntax when trying break the line of codes

    Hi all experts,

    Today I try to break a long code to multiple lines but Iface the same errors and I am clueless now about what I have done wrong

    My code is
    Code:
    gen small-samp = logFAT_w1 !=. & logTAT_w1 !=. & logCCC_w1 !=. & logOC_w1 !=. & lin_turn_w1 !=. & lrec_turn_w1 !=. & lpay_turn_w1 !=. &  lfirmsize_w1 !=. & ltangi_w1 !=. & fcf !=. & con_of_corr !=. & rul_of_law !=. & reg_qua !=. & gov_eff!=. & poli_stab !=. & voice_acc !=. & lngdp !=. & del_exc_rat !=.
    And it is too long for a line in do-file. So, I break the line, I tried two ways and they turned out that Invalid syntax

    First:

    Code:
    /*I inserted the "\" at the end of the first line*/
    Code:
      gen small-samp = logFAT_w1 !=. & logTAT_w1 !=. & logCCC_w1 !=. & logOC_w1 !=. & lin_turn_w1 !=. & lrec_turn_w1 !=. & lpay_turn_w1 !=. &  lfirmsize_w1 !=. & ltangi_w1 !=. & fcf !=. & con_of_corr !=. & rul_of_law !=. \
               & reg_qua !=. & gov_eff!=. & poli_stab !=. & voice_acc !=. & lngdp !=. & del_exc_rat !=.
    Second:
    Code:
    /*I inserted the "///" at the end of the first line*/
    Code:
      gen small-samp = logFAT_w1 !=. & logTAT_w1 !=. & logCCC_w1 !=. & logOC_w1 !=. & lin_turn_w1 !=. & lrec_turn_w1 !=. & lpay_turn_w1 !=. &  lfirmsize_w1 !=. & ltangi_w1 !=. & fcf !=. & con_of_corr !=. & rul_of_law !=. ///
               & reg_qua !=. & gov_eff!=. & poli_stab !=. & voice_acc !=. & lngdp !=. & del_exc_rat !=.
    Many thanks and best regards

    Last edited by Phuc Nguyen; 06 Jan 2023, 17:55.

  • #2
    Your syntax error is coming from the beginning of the line, not the break at the end. -gen small-samp = anything- will be a syntax error. small-samp is not a valid Stata variable name. Perhaps you meant -gen small_samp = ...-?

    By the way, you can save yourself some keystrokes and also make the code more readable with
    Code:
    gen legal_variable_name = !missing(logFAT_w1, logTAT_w1, logCCC_w1, logOC_w1, lin_turn_w1, lrec_turn_w1, lpay_turn_w1,  lfirmsize_w1, ltangi_w1, fcf, con_of_corr, rul_of_law, ///
               reg_qua, gov_eff, poli_stab, voice_acc, lngdp, del_exc_rat)
    This will do the same as your longer code on the assumption that you do not intend to treat missing values other than -.- differently, and are just interested in missingness of any kind.

    Comment


    • #3
      Thank you so much Clyde Schechter, yes, I did wrong at the beginning. And also thank you for helping me in shortening my code

      Comment

      Working...
      X