Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: exporting VCV to .csv format

From   baum <[email protected]>
To   [email protected]
Subject   st: Re: exporting VCV to .csv format
Date   Thu, 01 Aug 2002 10:17:56 -0400

--On Thursday, August 1, 2002 2:33 -0400 James wrote:

I am a new user of stata. I have a problem of exporting the
covariance-variance of estimate (after regress) to a external file with
extension, such as csv (or any data format with comma as seperation). The
command 'outsheet' is not working for this. Can someone tell me how to do
this? Thank you
This code fragment (hacked from -help file-) will do that, writing the file vcvout.csv. If it were made into a program, that would obviously be made the 'using' target.

* presume regress has been used to define e(V)
tempname hdl mname
file open `hdl' using vcvout.csv, replace write
mat `mname' = e(V)
local r = rowsof(`mname')
local names : colnames `mname'
local len : length local names
forvalues i=1/`r' {
local v : word `i' of `names'
file write `hdl' `"`v'"' (", ")
file write `hdl' _n
forvalues i=1(1)`r' {
forvalues j=1(1)`r' {
file write `hdl' (`mname'[`i',`j']) (", ")
file write `hdl' _n
file close `hdl'

The file which it creates reads into Excel just fine. If you wanted the row labels as well, that is easy to add in the second forvalues loop. The routine could also be generalized to deal with non-square matrices by retrieving the number of columns and the separate set of row names that would then apply.

* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index