Announcement

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

  • no observations to perfom with the code

    Code:
    asdoc cor gini_k decile incdegini eta agesquared  ncomp married self_employed smallcity disaving  debt_growthrate eyeah , label nonum replace
    Once I exceute the code stata informs me that there are no observations to perfom with this what should I do to rectify this

  • #2
    I am not an -asdoc- user, so I may be off base here. But as far as I understand it, you are trying to generate a correlation table among variables gini_k, decile, ..., eyeah. And you are getting a "no observations" error message.

    Stata's correlation command performs listwise deletion. That is, any observation in which any of the variables to be correlated is missing, will be omitted from the calculations. It seems that all of your data has a missing value in at least one of the variables you are trying to work with here, so none survives the omission process. One way that this can happen is if one of these variables is actually stored as a string in your data. So I would check for that first:
    Code:
    ds gini_k decile incdegini eta agesquared ncomp married self_employed smallcity disaving debt_growthrate eyeah, has(type string)
    If all of your variables are properly numeric, you will get no output from this command. If any of the variables is a string, however, Stata will tell you that. You will then have to deal with that variable and make it numeric. Without example data, I cannot advise you what the best method of doing that might be.

    If none of your variables is a string, then it is truly a problem of missing values somewhere in every observation. The command
    Code:
    misstable summarize gini_k decile incdegini eta agesquared ncomp married self_employed smallcity disaving debt_growthrate eyeah
    will give you information about total missingness in each variable.

    Whatever you find, the problem is ultimately that your data set cannot support the calculation you are trying to get Stata to do. So you will need to either drop some variable(s) from the analysis, change something(s) from string to numeric, or find a way to fill in at least some of the missing data.

    In the future, when asking for help with code, please post example data, and use the -dataex- command to do so. Had you posted example data here, it is likely I could have given you a fairly definitive explanation why you are encountering this problem.

    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.

    I should add that Stata has a command -pwcorr- which calculates correlation matrices using pairwise deletion. So if the problem is scattered missing data that affects some variables in each observation, but the data are numeric and there is no variable that is always missing, then you can get results with that. I do not know if -asdoc- supports -pwcorr-.
    Last edited by Clyde Schechter; 30 Apr 2022, 19:09.

    Comment


    • #3
      One way that this can happen is if one of these variables is actually stored as a string in your data.
      At least in Version 17, correlate takes care of that problem, and asdoc cor returns a different error than the one you report, so I expect the problem is with missing values.

      Code:
      . clear all
      
      . set obs 100
      Number of observations (_N) was 0, now 100.
      
      . generate x = runiform()
      
      . generate y = "1"
      
      . cor x y
      (y ignored because string variable)
      (obs=100)
      
                   |        x
      -------------+---------
                 x |   1.0000
      
      
      . asdoc cor x y
      (y ignored because string variable)
      (obs=100)
      
                   |        x
      -------------+---------
                 x |   1.0000
      
      (file Myfile.doc not found)
                    asdoccor():  3301  subscript invalid
                       <istmt>:     -  function returned error
      r(3301);
      And I would advise using the Stata correlate command until you resolve your problem, and then use that knowledge to construct your asdoc command. It's easier to debug a program if you start small and add complexity, rather than hope your perfect code will run perfectly the first time.
      Last edited by William Lisowski; 30 Apr 2022, 19:27.

      Comment


      • #4
        Very interesting. I was not aware that version 17's -corr- command would do that. Thanks for pointing that out.

        In a way, that's too bad for O.P., because of all the causes of -no observations-, a string variable is the easiest to fix.

        Comment


        • #5
          Thank you all for the help it worked.

          Comment

          Working...
          X