PHP Stata, read/write Stata files from within PHP language.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
config.m4
stata.c
stata.h
stataread.c
stataread.h
statawrite.c
swap_bytes.h

README.md

php_stata

PHP Extension for reading and writing STATA files

This extension was created to facilitate the data dissemination of the following projects:

  • Understanding America Study Datapages (http://uasdata.usc.edu)
  • Gateway to Global Aging Data (http://g2aging.org).

    1. Read and display Highcharts charts directly from Stata
    2. Provide descriptive information to the UAS Datapages viewers
    3. Generate question carts by opening and combining Stata files on the fly

    This PHP module has been tested using Apache.

    In order to compile the module, please type phpize on the directory to generate the config files.

    1. install php5-dev (for phpize)
    2. cd to directory with source files
    3. $ phpize
    4. $ ./configure
    5. $ make install
    6. On successful execution, the extension stata.so can be found in the subdirectory “modules”

    Example use:

    /* Reading */
    $res = stata_open("/var/www/html/filename.dta");
    
    echo "Stata observations: " . stata_observations($res);
    echo "Stata variables: " . stata_nvariables($res);
    
    
    print_r(stata_variables($res));
    
    $df = stata_data($res);
    
    echo $df['data'][0]['variablename']
    $labels = stata_labels($res)['labels'];
    stata_close($res);
    
    
    /* Writing */
    
    stata_write("filename.dta", array("data" => array( 1 => array("prim_key" => "232342342", 
                                                                  "testswitch" => 32.3234, 
                                                                  "mode" => 32741), 
                                                       2 => array("prim_key" => "33333333333333333", 
                                                                  "testswitch" => pow(2.0, 1023), 
                                                                  "mode" => 2147483621) )),  
                    
    		                            array("prim_key" =>   array("vlabels" => "",
                                                                            "dlabels" => "PRIM KEY",
                                                                            "vfmt" => "%17s",
                                                                            "valueType" => 20 ),
                                                      "testswitch" => array("vlabels" => "",
                                                                            "dlabels" => "TEST SWITCH",
                                                                            "vfmt" => "%9.0g",
                                                                            "valueType" => 255), 
                                                          "mode"  =>  array("vlabels" => "gfk2_live_vl5",
                                                                            "dlabels" => "INTERVIEW MODE", 
                                                                            "vfmt" => "%9.0g", 
    									"valueType" => 253)), 
                                               array("labels" => array( "gfk2_live_vl5" => 
                                                                                           array(44 => "44 Face" ,
                                                                                                 55 => "55 Call center")
    	                                                          )
    					    )
    				);