Announcement

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

  • matrix with loops

    Hi everyone, few hours ago I was having problems posting here something with rich text, so I hope everything goes fine now. I have a very small dataset of a survey of perceptions. I have six variables that are already means ( s1 s2...) and I have one variable with the name of the company I'm new working with matrix so I'm still having a hard time I want a matrix with the name of the company as row and the mean as colums this is my code, but it's not working # matrix drop _all matrix pearson=J(11, 6, .) scalar drop _all local c = 1 foreach x of varlist s1 s2 s3 s4 s5 s6 { local a = 1 foreach n of varlist cooperativa { svy: table `n', c( mean `x') matrix pearson[`a',`c']=e(mean) local a = `a' + 1 } local c = `c' + 1 } # stata output with this code is: "table is not supported by svy with vce(linearized); see help svy estimation for a list of Stata estimation commands that are supported by svy r(322);" Any ideas what I'm doing wrong or what should I do I would very much appreciate any help

  • #2
    What you are doing wrong was explained already in http://www.statalist.org/forums/foru...ing-to-missing and is explicit from FAQ Advice.

    Here is an edit of your post using CODE delimiters as recommended. Your main error, it seems, was typiing literal #, which just produces literal #.

    % begin edit

    I have a very small dataset of a survey of perceptions. I have six variables that are already means ( s1 s2...) and I have one variable with the name of the company.

    I'm new working with matrices so I'm still having a hard time. I want a matrix with the name of the company as row and the means as columns. This is my code, but it's not working

    Code:
    matrix drop _all
    matrix pearson=J(11, 6, .)
    scalar drop _all
    local c = 1
    foreach x of varlist s1 s2 s3 s4 s5 s6 {
         local a = 1
         foreach n of varlist cooperativa {
               svy: table `n', c( mean `x')
               matrix pearson[`a',`c']=e(mean)
               local a = `a' + 1
         }
         local c = `c' + 1
    }

    Stata output with this code is:

    "table is not supported by svy with vce(linearized); see help svy estimation for a list of Stata estimation commands that are supported by svy r(322);"

    Any ideas what I'm doing wrong or what should I do. I would very much appreciate any help.

    % end edit

    I will leave the question on svy to others who work with such commands.

    Your inner loop would not be a loop over the distinct values of the variable named. That is not how foreach works.

    More positively, there are more direct ways to get tables of means. Here's one:

    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . gen srep78 = string(rep78)
    
    . table srep78, c(mean mpg mean weight)
    
    --------------------------------------
       srep78 |    mean(mpg)  mean(weight)
    ----------+---------------------------
            . |         21.4         2,846
            1 |           21         3,100
            2 |       19.125       3,353.8
            3 |      19.4333         3,299
            4 |      21.6667         2,870
            5 |      27.3636       2,322.7
    --------------------------------------

    Comment


    • #3
      Thank you for editing, I really don“t know what wass happening. I thinks it was a browser or internet issue. At the end I did a simple table, is was easier because is a very small dataset, but I was trying to practice with matrix because I know is more efficient with larger ones. Thanks again!

      Comment

      Working...
      X