Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Mata - what comes after -st_addvar-?


From   [email protected] (William Gould, Stata)
To   [email protected]
Subject   Re: st: Mata - what comes after -st_addvar-?
Date   Tue, 05 Sep 2006 08:24:15 -0500

Danielle <[email protected]> wrote,

> Suppose I have a columnvector in Mata. I know I can use -st_addvar- to add a
> variable to the Stata dataset. But how do I fill in the values of that
> variable with the values of the Mata columnvector? (By now, I have pored
> through the manual, and I canno t find a reference to this!) Thanks,
> Danielle

You use -st_store()- and I apologize that, in the Also See in 
[M-5] st_addvar(), that was not mentioned.

Let's use the auto data,

        . sysuse auto, clear 

The auto data has 74 observations, so let's create a 74 x 1 vector and 
then use -st_addvar()- to create new variable -example- in the Stata 
dataset:

        . mata 

        : x = J(74, 1, 2)

        : st_addvar("float", "example")
        13

        : st_store(., "example", x)

        : end

        . describe
        <output shows now variable example>

        . list 
        <output shows new variable example contains 2 in every observation>

-- Bill
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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