# Available software
>Last modified: 19 Mar 2026
<div style="background-color: rgba(0, 178, 169, 0.3); padding: 5px; border-radius: 5px;"><strong>This guide details the software available in the UK LLC Trusted Research Environment (TRE).</strong></div>  
<br>

UK LLC supports researchers in using their preferred software packages. The following packages are **pre-installed** in the UK LLC TRE: 
* [SQL Server Management Studio](#sql-server-management-studio)
* [Python](#python)
* [R and RStudio](#r-and-rstudio)
* [Stata](#stata)
* Jupyter Notebooks
* SPSS   

If you prefer to use **other software**, please contact [**support@ukllc.ac.uk**](mailto:support@ukllc.ac.uk) and the UK LLC Data Team will coordinate review of your request. Please be aware that alternative software packages may incur a fee. 

## SQL Server Management Studio  
SQL Server Management Studio can be used to **view and query your data**. To explore your database views, open the software package and connect to the server ‘**SERPSQL**’. Under ‘Databases’ in the Object Explorer, navigate to the ‘**UKSERPUKLLC**’ folder, where you can explore your ‘**Views**’ and '**Tables**'. Data and metadata are found in ‘Views’ and Codelists in ‘Tables’.  

To **browse the data** in a specific view, right click on the view name and ‘**Select Top 1000 Rows**’. This will produce a grid-view of the first 1,000 rows of data and a query window where data can be queried using SQL commands. This also works for tables.  

Click on the YouTube link below for a short video guide (70 seconds).

[![Image alt text](https://img.youtube.com/vi/e2nrAly21Uo/0.jpg)](https://www.youtube.com/watch?v=e2nrAly21Uo)


## Python
To use python and install any packages, you need to create your own **Anaconda environment**. You should do this **before running any code**. This enables you to pip and conda install packages **without barriers**. 

### Creating a new environment
Click on the YouTube link below for a short video guide (60 seconds).

[![Image alt text](https://img.youtube.com/vi/kMeMBASgSQ0/0.jpg)](https://www.youtube.com/watch?v=kMeMBASgSQ0)


We provide an **automatic means** of creating an environment, but you are welcome to create your own environment independently if you prefer. To choose the automatic pathway, double click on: '**S:\ReadAll\python_help\env_helper\create_python_env.bat**'. This creates a new environment as a **clone of the base environment**, meaning all standard packages in the base Anaconda installation will be included.   

**Things to be aware of whilst the environment is being created**:
1.	Creating a new environment can take around **2 hours**, but you can leave this running in the background. 
2.	The terminal may print '**The following packages cannot be cloned out of the root environment:...**' This is expected and the environment should still create despite this message.
3.	At the end of the process, you will see the following **warning message**. This can be closed. It will appear 4 times. Your environment will still be **successfully created** despite the warning.
 
<img src="../images/user_guide/image-10.png" width="500"/>


Once complete the script will have created a **new environment** in the location: '**P:/%USERNAME%/envs**' called '**env1**'. Therefore, the **environment name** will be '**P:/%USERNAME%/envs/env1**'.

The **batch file** ('create_python_env.bat') can be **edited** if you wish to store your environment in a **different location** or would like to **name it differently**. Please take a **copy** of the batch file and **save it** in your project area before editing. The environment will be created in the P: drive because this is a drive available only to you and accessible from whichever remote desktop you are assigned on login.

### Using your new environment
<aside class="admonition danger"><p class="admonition-title">ALWAYS SAVE YOUR WORK ON THE P:\ OR S:\ DRIVE</p>Once you log off, restart or shutdown the virtual machine that you are using in the TRE, the machine is rebuilt and the majority of the C:\ drive wiped.</aside>  
<br>

If you are using **Jupyter Notebooks, Spyder** or any other **Anaconda tools** for your analyses it is recommended that you launch these from Anaconda Prompt **after activating your new environment**. This will ensure you are running your new environment within the application. To do this:
1. Launch **Anaconda Prompt**.
2. Type: **P:**
3. Type: **cd %USERNAME%**
4. Type: **conda activate "P:/%USERNAME%/envs/env1"**
5. From within Anaconda Prompt type the name of the **application you want to run**: eg “spyder” or “jupyter notebook”. 

>**Note:** please replace **%USERNAME%** with your own TRE username.

### Using the Python helper
Click on the YouTube link below for a short video guide (60 seconds).

[![Image alt text](https://img.youtube.com/vi/29pMeZ3DQPw/0.jpg)](https://www.youtube.com/watch?v=29pMeZ3DQPw)

We recommend using **Juypter notebook** and we have prepared a template notebook with a comprehensive suite of helper functions. You will find this in: '**S:\ReadAll\python_help\notebook_helper**'. There are two files of note here, '**notebook_template.ipynb** and '**notebook_helper.py**'. Make sure to copy them both into your project’s working directory. The notebook template will guide you through how to pull your data and operate on it, using functions from the notebook helper program. You needn’t look into the underlying code in the notebook helper, but you are welcome to make changes should you wish. 

**Note**: for **Jupyter notebooks** you may want to change directory to your working directory **before running the application**.

## R and RStudio
### Using the R helper
Click on the YouTube link below for a short video guide (120 seconds).

[![Image alt text](https://img.youtube.com/vi/IqLUcMsK5Ac/0.jpg)](https://www.youtube.com/watch?v=IqLUcMsK5Ac)

If you are planning on using R, an **R helper** is provided in '**S:\ReadAll\r_help**'. These scripts are designed to help you extract your data from the database and to add **variable** and **value labels** using the **expss R package**. 

The **R helper** specifies the version of R that is required. For more information on how to change your R version please see the section 'Specifying the version of R within RStudio' in the next section.

To use the R helper:
1.	Take copies of both scripts '**r_label_helper.R**' and '**r_label_functions.R**' and save copies to your working area. This is because you will need to **edit** 'r_label_helper.R' with your project specifics and requirements.
2.	Once you have **local copies**, ensure both scripts are in the **same directory** because '**r_label_helper.R**' will expect to find '**r_label_functions.R**' 
3. Open '**r_label_helper.R**' with **RStudio** and find the comment '**ACTION1: enter/update project number...**'. Update the **proj_no variable** to your project number in the form '**LLC_XXXX**'  
<img src="../images/user_guide/image-9.png" width="600"/>

4.	**Run the script** up to and including:  
<img src="../images/user_guide/image-8.png" width="600"/> 

    **N.B.** It can take up to 30 minutes to load in the packages.

5.	You will see a **list of your project views** printed to the console and a '**viewnames**' variable will be created in your environment. Check 'viewnames' are consistent with your expectation.  
6.	View the remainder of the script. There are **three options** pre-scripted for **retrieving data** from the database and adding the **variable and value labels**:  

*   One **table** at a time.  
*   One **LPS/data source** at a time e.g. MCS.  
*   **All tables** at once (not recommended due to performance issues).


### Method 1 - one table at a time
1.	Under **ACTION2a** update the ***data_source*** and ***table*** name variables using lowercase e.g.  
<img src="../images/user_guide/image-7.png" width="600"/>

2.	Note your views are in the example form '**LLC_0001.<span style="color:red">GENSCOT<span style="color:black">_COVIDLIFE1_v0001_20211101**'
3.	The ***data_source*** (usually LPS name) is in **<span style="color:red"> red**, separated by the descriptive part (+versions and date) by an underscore. You will need to isolate these and assign to the ***data_source*** and ***table*** variables separately as shown above.

### Method 2 - one LPS/data source at a time
1.	Under **ACTION2b** update the ***data_source*** only using lowercase e.g.  
<img src="../images/user_guide/image-6.png" width="600"/>

2.	This will retrieve all views from that data source and apply value and variable labelling. The output will be stored as a list of dataframes called “one_stud_dfs_w_labs”. 

### Method 3 - load all data at once
1.	No update to script required here. Run code underneath:  
<img src="../images/user_guide/image-5.png" width="600"/>

2.	As stated in the comments, this method is not recommended if you have a large number of datasets because these will be slow to retrieve and add labels to.  

You are welcome to modify the 'r_label_helper.R' to suit your use case and to use the example syntax to apply labelling to your own subsets of tables.

### Specifying the version of R within RStudio
Should you wish to change the version of R being used by RStudio. Ensure that if your library is setup to match the R version e.g. for 4.5.0, you need to set R to 4.5.0. You can do this with the following method:

Change R within RStudio:

1. Go to Tools > Global options
2. Click 'Change...' under R version
3. Click the 'Choose a specific version of R' option
4. Select the version of R.
5. Click Okay
6. Click Apply

Change R on launch of RStudio:

Hold the CTRL key and double click the RStudio launcher, as shown below:  
<img src="../../docs/user_guide/images/R_install.png" width="600"/>


Doing this will change the folder in which RStudio loads your library, as shown above, if you select 4.5.0, the library path will be P:\%USERNAME%\AppData\Roaming\R\4.5.0\Library

If you are having issues with upgrading R and package compatibility issues, please consult the following [article](https://rpubs.com/wch/275466#:~:text=Sometimes%20packages%20installed%20with%20a,an%20old%20version%20of%20R.). 

For more information on using R and R studio in the TRE  visit the [SeRP guidance](https://ukserp.atlassian.net/wiki/spaces/HDK/pages/16712639/RStudio+and+R).

## Stata
The 'Stata helper' script in the TRE extracts and labels all the datasets provisioned to your project, saving them in your project working space. Alternatively, you can manually retrieve and label the data one table at a time. 

### Using the Stata helper  
**N.B. Before using the Stata helper, you need to create a python environment.** The steps for doing this are described in ['Creating a new environment'](#creating-a-new-environment) above.

Once you have created a your python environment, click on the Youtube link below for a short video guide (60 seconds) to using the Stata helper.

[![Image alt text](https://img.youtube.com/vi/arWQzkiQcv0/0.jpg)](https://www.youtube.com/watch?v=arWQzkiQcv0)


The Stata helper script is provided in the folder '**S:\ReadAll\stata_help**'. The batch file 'run_stata_helper.bat' runs the script 'py_stata_helper.py'. This python script will extract data from your project views, add variable and value labels and save **stata format (.dta) files** to your project working space in the folder 'S:\LLC_XXXX\data\stata_w_labs'.  

To use the helper:
1. Search for Stata19 in the Windows Start Menu, then open and immediately close the Stata19 app. (This step 'delivers' the software to the virtual desktop.)
2. Create your own python environment if you have not already done so (see ['Creating a new environment'](#creating-a-new-environment) above).
3. When the new environment has been created, double click on 'S:\ReadAll\stata_help\run_stata_helper.bat'.
4. When asked, input your project number as four numbers, e.g. 9999.
5. The command prompt will print to inform you when a dataset has been retrieved and whether value and variable labels have been found. 
6. The files will be saved in .dta format in 'S:\LLC_XXXX\data\stata_w_labs' and can be opened in Stata.

**Note**: if your project has been provisioned a large number of views this process can take up to an hour to complete.

### Manually retrieve and label data
To retrieve the full contents of a data view in Stata run:
*odbc load, exec(“select * from #INSERTVIEWNAME#”) dsn(LLC_DB)*  

View names can be found in the '**available_views**' folder in your project space. Replace #INSERTVIEWNAME# with the view name you’d like to retrieve. This must include schema, which is usually your project number e.g.
*odbc load, exec('select * from LLC_9999.bcs70_basic_demographic_v0001_20211101') dsn(LLC_DB)*  

Variables and value labels can be retrieved via the following database views: 
* DESCS.all_descriptions – for **variable** labels
* VALUE.all_values – for **value** labels.

### Using Stata with Jupyter Notebook
If using Stata, we recommend building your analyses into a **Jupyter Notebook**. Jupyter Notebook allows you to execute code and to create visualisations with narrative text in one document (a 'notebook'). This enables researchers to easily **share their code** and **research findings**. If you are new to Jupyter, we recommended that you familiarise yourself using online tutorial/training material.

Stata in Jupyter is invoked using the **IPython kernal**, so you can use Python and Stata in the same environment. To use Stata within Jupyter you will first need to [**create your own python environment**](#creating-a-new-environment) and run the [**Stata helper**](#using-the-stata-helper) to convert your database views into Stata files. Once you’ve completed these two steps, you can begin with Stata in Jupyter:
1.	Launch Anaconda Prompt by typing into the Search bar.
2.	Type: *conda activate "P:/%USERNAME%/envs/env1"* replacing %USERNAME% with your actual username. This will switch you to your custom environment.
3.	Change directory to where you want to save your workings by typing: *S:* and then *cd "LLC_9999\syntax"* replacing "*LLC_9999\syntax"* with target working directory.
4.	Within Anaconda Prompt type: *jupyter notebook*. This will launch Jupyter Notebook with your custom environment and working directory pre-configured. 
5.	When Jupyter has loaded, select 'New' and 'Python 3' (Warning 404 message will flash up for approx. 10 secs – ignore):  
<img src="../images/user_guide/image-13.png" width="700"/>
6.	You are now ready to execute code. In cell 1 type: *pip install --upgrade --user stata_setup*. Then press the **>Run** button on the menu bar.
7. In cell 2 type: *import stata_setup*  **>Run**
8. In cell 3 type: *stata_setup.config(‘C:/Program Files/Stata18’, ‘se’)*  **>Run**

This will configure your stata setup:  
<img src="../images/user_guide/image-12.png" width="700"/>

9.	You can then load a dataset and begin analyses. In each cell you intend to run stata code the first line must begin with *%%stata*. See the example below:  
<img src="../images/user_guide/image-11.png" width="700"/>

