Announcement

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

  • Problem with coding

    I have tried running the Stata code but keep getting a error message "( is not a valid command name". please, what could be the problem?
    Attached Files

  • #2
    Hello Folarin Alale. Many forum members are reluctant to open attached Word documents. Please paste the problematic code directly into your post, highlight it, and then click on the # tool in the toolbar to enclose it in CODE delimiters. See also Section 12.2 of the FAQ.
    12.2 What to say about your data

    We can understand your dataset only to the extent that you explain it clearly.

    The best way to explain it is to show an example. The community-contributed command dataex makes it easy to give simple example datasets in postings. It was written to support Statalist and its use is strongly recommended. Usually a copy of 20 or so observations from your dataset is enough to show your problem. See help dataex for details.

    As from Stata 15.1 (and 14.2 from 19 December 2017), dataex is included with the official Stata distribution. Users of Stata 15 (or 14) must update to benefit from this. Users of Stata 16 or 17 need not do anything: dataex is already part of your installation.

    Users of earlier versions of Stata must install dataex from SSC before they can use it. Type ssc install dataex in your Stata.

    The merits of dataex are that we see your data as you do in your Stata. We see whether variables are numeric or string, whether you have value labels defined and what is a consequence of a particular display format. This is especially important if you have date variables. We can copy and paste easily into our own Stata to work with your data.

    If your dataset is confidential, then provide a fake example instead.

    The second best way to explain your situation is to use one of Stata's own datasets and adapt it to your problem. Examples are the auto data and the Grunfeld data (a simple panel dataset). That may be more work for you and you may not find an analog of your problem with such a dataset.

    The worst way to explain your situation is to describe your data vaguely without a concrete example. Note that it doesn't help us much even to be given your variable names. Often that leaves unclear both your data structure and whether variables are numeric or string or their exact contents. If you explain only vaguely, quick answers to your question, or even any answers at all, are less likely.
    HTH.
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 19.5 (Windows)

    Comment


    • #3
      Hi Bruce Weaver Thanks for your comment and enlightenment. I'm sorry for my ignorance, as I 'm new on the Forum.

      The dataset entry.dta contains a cross-section of 661 routes covered by the top seven US airline companies. In the dataset a market is a city-pair. The firms are American (id=1), Delta (id=2), Southwest (id=3), Continental (id=4), US Airways (id=5), United (id=6), and Northwest (id=7). The variables are market size (pop, the product of populations of both end points of the city pair), a tourist dummy (tourist, set to one for route markets where at least one of the two end point cities are either in California or in Florida and for Aspen and Colorado Spring), distance (dist, measured in km between end point cities), a two-hub dummy (twohub, set to one for city pairs where both end points qualify as large hubs), one-hub dummy (onehub, set to one for route markets with one end point as a large hub), en entry dummy (entry, set to 1 if the airline is in that market), the number of airlines in the market (N, note that this can be zero if there are not top seven airlines in that market), an identifier for the market (mk) and the name of the market (routemarkets).

      I’m trying to calculate the expected number of routes each airline is present and compare it with the actual number by using a linear probability model, probit model first, and then a logit model. Also I want to know all three econometric specifications (linear, probit, and logit) lead to the same expected number of entry routes by the airline? Which one is preferred based on a comparison between the expected number of entry routes and the observed number of entry routes?

      // Calculate expected number of routes using the probit model
      Code:
      egen expected_routes_probit = rowtotal((id == 1) & p_entry_probit ///
                                             (id == 2) & p_entry_probit ///
                                             (id == 3) & p_entry_probit ///
                                             (id == 4) & p_entry_probit ///
                                             (id == 5) & p_entry_probit ///
                                             (id == 6) & p_entry_probit ///
                                             (id == 7) & p_entry_probit)
      // Calculate expected number of routes using the logit model
      Code:
      egen expected_routes_logit = rowtotal((id == 1) & p_entry_logit ///
                                            (id == 2) & p_entry_logit ///
                                            (id == 3) & p_entry_logit ///
                                            (id == 4) & p_entry_logit ///
                                            (id == 5) & p_entry_logit ///
                                            (id == 6) & p_entry_logit ///
                                            (id == 7) & p_entry_logit)

      Comment


      • #4
        I'll start at the egen end. The function rowtotal() wants a varlist and that means a list of one or more variable names. Anything else presented will trigger a syntax error.

        What you presented is not a varlist and not even a legal expression, as it is a list of expressions like (id == 1) * p_entry_logit with no operators linking them.

        Someone else should be able to follow what you want from a model end.

        Comment


        • #5
          Nick Cox how do you think I can correct the error? I am not getting a varlist error message. These are the error message I keep getting "parentheses unbalanced" and "( is not a valid command name". Below are the preceding codes for estimating probit and logit

          // Estimate probit model
          Code:
          probit entry pop tourist dist twohub onehub N, robust
          predict p_probit
          gen p_entry_probit = normal(p_probit)
          // Estimate logit model
          Code:
          logit entry pop tourist dist twohub onehub N, robust
          predict p_logit
          gen p_entry_logit = logistic(p_logit)

          Comment


          • #6
            As said you need someone who understands your goal to suggest code. My guess is that rowtotal() is irrelevant.

            Comment


            • #7
              Thanks Nick

              Comment


              • #8
                I am not getting a varlist error message. These are the error message I keep getting "parentheses unbalanced" and "( is not a valid command name".
                Just a general comment: it is best to take Stata error messages seriously, but not literally.

                Stata's syntax parser is not AI based: it tries to match up user input with allowable syntactic structures, proceeding through the in put one or a small number of "words" at a time. When no match can be found, it throws an error and gives a message that is often informative about the actual problem. But sometimes, as here, the input is so far away from any acceptable syntax that the parser simply "has no idea" what is going on. In many such situations it will provide a very generic error message such as "syntax error" and leave it to the user to figure out what is going on. Sometimes it throws a more specific message. While it is usually a good idea to start out assuming that the error message is on point, if serious effort by the user does not lead to understanding the problem, the next step is to assume that perhaps the parser just "got confused" and that the particular error message is not on point. Then you have to resume the debugging with a wider perspective about what might be wrong.

                One might wish for a more sophisticated parser that gives better diagnostics when it finds errors. But if you have ever tried to develop such a program, you will appreciate just how difficult it is to guess what is going wrong when you are many layers down in a parse and encounter a dead-end: the problem could have arisen anywhere along the way, and figuring it out from the current state of the parse can be overwhelmingly difficult.

                Comment

                Working...
                X