Announcement

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

  • abnormal cash flow from operation every year and industry

    When I do the regression of "abnormal cash flow from operation every year and industry " , only the last step not working, here is the code

    Initially

    Drop missing values for the variables in equation 1 of the tutorial

    ------------------------------------------------------------------------------*/

    drop if missing(cfo_at)
    drop if missing(one_at)
    drop if missing(sales_at)
    drop if missing(deltasales_at)




    /*------------------------------------------------------------------------------

    STEP A

    Drop regulated industries & banks and financial institutions

    ------------------------------------------------------------------------------*/


    // Drop regulated industries
    destring sic, replace // Transform sic codes to numeric format
    drop if inrange(sic,4400,5000) // Drop sic codes between 4400 and 5000

    // Drop banks and financial institutions
    drop if inrange(sic,6000,6500) // Drop sic codes between 6000 and 6500





    /*------------------------------------------------------------------------------

    STEP B

    Keep only more than 15 observations per industry-year group

    ------------------------------------------------------------------------------*/


    tostring sic, replace // Transform sic codes to string format
    gen sic2=substr(sic,1,2)
    destring sic2, replace sic2: all characters numeric; replaced as byte
    drop if missing(sic2) (0 observations deleted)
    egen sic2id = group(sic2 fyear) // Create unique identifier for year-industry group
    egen count = count(sic2id), by(sic2id) // Count the nr of firms within year-industry group
    keep if count >= 15 // Keep firms with more than 15 firms in year-industry group






















    /*------------------------------------------------------------------------------

    STEP C

    Calculating the Abnormal CFO per year & industry

    ------------------------------------------------------------------------------*/

    set more off

    gen ABN_CFO = . // Abnormal CFO. First you create an empty variable. This will be filled in.

    drop sic2id
    egen sic2id = group(sic2 fyear) // Create unique identifier for year-industry group

    Variable | Obs Mean Std. Dev. Min Max
    -------------+---------------------------------------------------------
    sic2id | 61,671 448.1137 251.5735 1 900

    .

    local max=r(max)
    only this part below cannot working , or it shows nothing just like this
    Click image for larger version

Name:	2022-07-16 19.29.11.png
Views:	1
Size:	334.7 KB
ID:	1673799

    forvalues i = 1/`max' {

    di "Busy with regression " `i' " of " `max'
    qui reg cfo_at one_at sales_at deltasales_at if sic2id == `i'
    qui predict res if sic2id == `i', res
    qui replace ABN_CFO = res if sic2id == `i'
    qui drop res

    }

  • #2
    It is never a good idea to simply say that something is "not working." You need to say what exactly it is doing, and in what way that differs from what you wanted to happen. It is also always a good idea to provide example data, using the -dataex- command whenever you want help with troubleshooting code. 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.

    That said, the code that shows up in your screenshot has one obvious problem: the opening brace at the end of the -forvalues i = 1/`max' {- command at the very top of the screenshot has no corresponding closing brace. You need to put one there: line 7 should look like lines 12 and 19.

    I also don't understand why you are repeating the same code three times. The results will be the same each time, so you only need to do it once.

    Comment

    Working...
    X