Announcement

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

  • Error Code (199)

    Hello Everyone,
    I'm Kousay, and I'm conducting research on the impact of the pandemic on the firm financial performance. To represent the firm's total financial performance, I have chosen several variables. Still, as I am unable to add them, I need to generate a new variable called "score" in Stata using the following commands. However, when I run the last command, I encounter an error code (198). I have already checked all the variables and ensured there are no missing values and verified the spelling, but I still can't locate this new variable score. I hope to receive some help as this is the dependent variable for my regression.
    following are the command Im using
    // Define weights for each variable
    local weights "0.2 0.3 0.2 0.2 0.1"

    // Define variables to include in the analysis
    local variables "ROA ROE EPS earnings_growth revenue_growth"

    // Generate a new variable as the weighted sum of the selected variables
    egen score = rowtotal ROA ROE EPS earnings_growth revenue_growth /wordcount ROA ROE EPS earnings_growth revenue_growth/ 5 * 0.2 0.3 0.1 0.2 0.2


    this last step to generate the new variable score, I get this error r(198)

    If anyone has any suggestions on what might be causing this error or any tips on how to fix it, please let me know. I would greatly appreciate any help you can offer!

    Thank you in advance.

  • #2
    The syntax of your -egen score ...- command is wrong in several ways.

    First, you need the things that are being added up to be in parentheses. So like:
    Code:
    egen score = rowtotal(ROA ROE EPS earnings_growth revenue_growth) 
    But that would just give you an unweighted mean. In fact, you can't get a weighted sum or mean from -egen-. And you can't do any further calculations beyond the -rowtotal()- function in -egen-. Moreover, the final part -* 0.2 0.3 0.1 0.2 0.2- does not tell Stata to apply those five numbers as weights. In fact, Stata would have no idea what to do with those.

    If the real problem involves only these five variables, the simplest way to do this is:
    Code:
    gen score = 5*(0.2*ROA + 0.3*ROE + 0.1*EPS + 0.2*earnings_growth + 0.2*revenue_growth)
    Now, if you actually have a much larger number of variables, I would do it in a loop:
    Code:
    // Define weights for each variable
    local weights 0.2 0.3 0.2 0.2 0.1
    
    // Define variables to include in the analysis
    local variables ROA ROE EPS earnings_growth revenue_growth
    
    local nvars: word count `variables'
    assert `nvars' == `:word count `weights''
    
    gen score = 0
    forvalues i = 1/`nvars' {
        replace score = score + `:word `i' of `weights'' * `:word `i' of `variables''
    }
    replace score = score * `nvars'

    Comment


    • #3
      Thank you so much!

      Comment


      • #4
        Hello everyone,

        I am working on a project and need some help creating a graph in Stata to show the growth in sales aggregated to the industry level. Specifically, I want to compare the sales growth in 2020 and 2022 to the sales growth in 2018 and 2019, respectively.

        I have all the necessary data in Stata and have already calculated the sales growth rate by industry and year. However, I am not sure how to create the graph that I need.

        Could someone please help me with the code to create this graph in Stata? I would like the graph to have the following features:
        • Aggregated by industry
        • Show the sales growth rate on the y-axis
        • Show the year on the x-axis, with tick marks for 2018, 2019, 2020, and 2022
        • Title: "Sales Growth by Industry, 2018-2022"
        • Subtitle: "Aggregated by Industry in 2020 and 2022"
        • Y-axis label: "Sales Growth Rate"
        • X-axis label: "Year"
        Thank you in advance for any help or guidance you can provide.

        Comment


        • #5
          This question is unrelated to the topic of the original thread. While it is easy to think of these threads as dialogs between questioners and responders, in fact, this Forum is searched by people looking to answer questions on specific topics. To avoid wasting their time, or making helpful advice unavailable because it is "hidden" from them, it is important to keep threads on topic. Please repost your question as a New Topic.

          Also, when you do that, be sure to give example data, using the -dataex- command. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

          Comment

          Working...
          X