Announcement

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

  • How to save a list of Alphas?

    I created many new variables (around 40) in a dataset based on existing old variables. I plan to get the Cronbach's Alphas of all the new variables and save them to a new file. The way I am creating the variables and getting the alphas is as the following:

    Code:
    alpha x1 x2 x3 x4, gen(x)
    scalar a_x=r(alpha)
    //assume a_x=0.9
    
    alpha w1 w2 w3 w4 w5 w6 w7 w8, gen(w)
    scalar a_w=r(alpha)
    //assume a_w=0.7
    
    alpha s1 s2 s3, gen(s)
    scalar a_s=r(alpha)
    //assume a_w=0.8
    I would like to name/label a_x, a_w, and a_s as "Alpha X", “W's alpha”, and "The alpha of s". Then, save them to an excel file with two columns like this:

    Code:
    Variables              Alphas
    Alpha X                0.9
    W's alpha             0.7
    The alpha of s      0.8
    Is there a way to do so? I thought of the -matrix- command but didn't figure out how...

  • #2




    Code:
     **example - paste in do-file editor
    *Use an example dataset
        sysuse auto, clear
    *Use putexcel to create excel file. First, set the column headers:    
        putexcel set myalpha, replace
        putexcel A1 = ("Group"), border(bottom, medium)
        putexcel B1 = ("Alpha"), border(bottom, medium)
    *Rather than build each row manuall, use a loop. The `i` macro will contain the starting row for the alpha values (starts on row 2 since the header row is on row 1) and it is iterated each time using the macro expansion operator `++`
        loc i = 2
        foreach j in "mpg headroom t*"  "mpg  t*"  "headroom for price" {
        putexcel A`i' = ("Alpha group `i'")
            alpha `j'
            di in red `r(alpha)'
        putexcel B`i' = `r(alpha)', nformat(number_d2)
        loc `++i'
        }
    *Close out the file and open excel to view file:    
        putexcel close
    Eric A. Booth | Senior Director of Research | Far Harbor | Austin TX

    Comment


    • #3
      Hello eric_a_booth,

      I hope this message finds you well!

      I am trying to use strategies you suggested to Victor to output results from "alpha" that are repeated on 15 cycles of data.

      Currently I have the below code but I am not really sure where and how to integrate your suggestions. Do you have any recommendations?


      Code:
      forval i=1/15 {
      alpha q7pamotiv1 q7pamotiv13 q7pamotiv16 q7pamotiv19 ///
      q7pamotiv23 if Cycle=="Cycle `i'", item
      }
      Thank you for your time,
      Best wishes

      Patrick

      Comment

      Working...
      X